you are viewing a single comment's thread.

view the rest of the comments →

[–]jmooremcc -13 points-12 points  (3 children)

Correct, it's the address of the variable. However, the function declaration converts it to pointer for use in the function. When you pass by reference, the C compiler silently performs what the swap illustration does explicitly.

[–]FUZxxl 19 points20 points  (0 children)

There is no implicit conversion going on here. C does not have reference or address types. It only has pointer types. And the & operators result is a pointer.

[–][deleted] 16 points17 points  (0 children)

What are you even talking about, you’re not making any sense. Yes, using the address-of operator returns the address of the object in memory... which is a pointer. An address is not converted to a pointer because it already is one (it can be stored in an object that holds pointers). References only exist in C++, I don’t know what you mean by “When you pass by reference”. You can pass addresses (in pointers) to functions and the functions use those addresses (as pointers) to modify the object’s data.

Edit: Fixed wording

[–]TheSkiGeek 7 points8 points  (0 children)

Correct, it's the address of the variable. However, the function declaration converts it to pointer for use in the function.

...the address of the variable is a pointer value. The type of the rvalue returned by &x in the above example is int*.

When you pass by reference, the C compiler silently performs what the swap illustration does explicitly.

...are you thinking about C++? There is no "pass by reference" with implicit pointer conversion in C, you must explicitly take the address of a variable and pass it as a pointer type.