Arguments Passing Techniques:


Argument passing is a process of transferring data between the calling function and the called function. In C, there are two ways by which arguments can be passed.
a.      Pass by value

b.      Pass by reference

Pass by Value:
The pass by value is the default mechanism for argument passing. When an argument is passed by value then a copy of argument(s) is made passed to the newly created formal argument(s) in the called function. Since the formal arguments contains a copy of the actual argument(s) which is stored in separate memory location so any changes made to these are not reflected back to the actual argument(s). The changes made in the formal argument(s) are local to the block which are lost once the control is returned back to the calling function.




Pass by Reference:


 The pass by reference is another mechanism of passing argument(s) to a function. Unlike pass by value method where a copy of argument(s) is passed, in pass by reference method, the address of argument(s) is passed to the called function. If any modifications are made to the formal arguments then those changes are reflected back to the actual arguments. The address of argument(s) is passed by preceding the address operator (&) with the name of variable(s) whose value you want to modify. The corresponding formal argument(s) are proceeded with asterisk (*) which acts as a pointer variable to store the address of the actual argument(s).




Previous                                                                                    Next


Powered by Blogger.