|
|
|
|
Calling The Function by Reference
In call by reference, the function is allowed access to the actual memory location of the argument and therefore can change the value the arguments of the calling routine. There may be, cases, where values of the arguments of the calling routine have to be changed. A function is written which takes two arguments interchanges their values and returns them. Function swap interchanges the values of u and v, but these values are not passed back to the main(). As discussed earlier, this is because variables u and v in swap() are different from the variables u and v in main(). In a case like this, a call by reference can be used to achieve the desired result, because it will change the values of actual arguments. Pointers are used when a call by reference has to be made. #include
<stdio.h> |