The pointer is send to the subprogram and no actual data is copied at all. The main advantage with this technique is that its absolutely efficient in time and space because there is no need to duplicate space and there is no data copying operations.Ĭ implements pass-by-value and also pass-by-reference (inout mode) semantics using pointers as parameters. In this strategy the subprogram has direct access to the data effectively sharing the data with the main routine. Instead of copying data back and forth between the main routine and the subprogram, the runtime system sends a direct access path to the data for the subprogram. Pass-by-reference is the second technique for inout-mode parameter passing. Pass-by-Value-Result (inout mode semantics) Several models have been devised by language designers to implement these three elementary parameter passing strategies: These models are commonly known as in mode, out mode, and inout mode, correspondingly. While implementing parameter passing, designers of programming languages use three different strategies (or semantic models): transfer data to the subprogram, receive data from the subprogram, or do both. Short answer: Yes, C does implement parameter passing by reference using pointers. Otherwise ptr would be NULL after function invocation. In my opinion this proves clearly that pointers are passed-by-value. The result will be that the two addresses are equal (don't worry about the exact value).Įxample result: param's address -1846583468 How can we show/prove that fact? Well, maybe we can try the first example of Scalar variables, but instead of scalar we use addresses (pointers). The int type value was incremented, and that is the side effect that make us think that it was a pass-by-reference function call. It was passed by value, the param value being an address. That makes you believe that the parameter was passed by reference. Printf("I've received value %d\n", *param) Printf("I've received value %d\n", param) Note incrementing param in the function does not change variable. param is called the formal parameter and variable at function invocation is called actual parameter. This short program shows pass-by-value using a scalar variable. Let's try to see the differences between scalar and pointer parameters of a function. Passing a pointerĪs a parameter does not mean pass-by-reference.Ī function is not able to change the actual parameters value. The C language is pass-by-value without exception. That is not pass-by-reference, that is pass-by-value as others stated.