Does C have references?

CReference

C Problem Overview


Does C have references? i.e. as in C++ :

void foo(int &i)

C Solutions


Solution 1 - C

No, it doesn't. It has pointers, but they're not quite the same thing.

In particular, all arguments in C are passed by value, rather than pass-by-reference being available as in C++. Of course, you can sort of simulate pass-by-reference via pointers:

void foo(int *x)
{
    *x = 10;
}

...

int y = 0;
foo(&y); // Pass the pointer by value
// The value of y is now 10

For more details about the differences between pointers and references, see this SO question. (And please don't ask me, as I'm not a C or C++ programmer :)

Solution 2 - C

Conceptually, C has references, since pointers reference other objects.

Syntactically, C does not have references as C++ does.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionjacky jackView Question on Stackoverflow
Solution 1 - CJon SkeetView Answer on Stackoverflow
Solution 2 - CsbiView Answer on Stackoverflow