Interview Questions

So arrays are passed by reference...

C Interview Questions and Answers


(Continued from previous question...)

So arrays are passed by reference...

Q: So arrays are passed by reference, even though the rest of C uses pass by value?

Not really.

Strictly speaking, C always uses pass by value. You can simulate pass by reference yourself, by defining functions which accept pointers and then using the & operator when calling, and the compiler will essentially simulate it for you when you pass an array to a function
Another way of looking at it is that if an parameter has type, say, int * then an integer is being passed by reference and a pointer to an integer is being passed by value.
Fundamentally, C has nothing truly equivalent to formal pass by reference or C++ reference parameters. (On the other hand, function-like preprocessor macros can provide a form of ``pass by name''.)

(Continued on next question...)

Other Interview Questions