Does C have references?

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 🙂

Leave a Comment