When a function is called by the calling program, the values to the arguments in the function are supplied by the calling program. The values supplied can be used inside the function. Any alteration to the value inside the function is not accepted in the calling program but the change is locally avaliable in the function. This method is referred as calling a function by value.
|
When this program executed, values of the variables a and b are printed before and after the function call and also inside the function as shown below :
A function can be declared with pointers as its arguments. Such functions are called by the calling program with the address of a variable as argument from it. The address of the variables are substituted to the pointers and any alteration to its value inside the function is automatically carried out in that location. The change is indirectly made and is accepted by the calling program. This method is referred as calling a function by reference.
|
When this program executed, values of the variables a and b are printed before and after the function call and also inside the function as shown below :
Note : That the increase in values of the arguments a and b is available in the main program also.
Call by Value | Call by Reference |
---|---|
|
|
It's a special area where you can find special questions and answers for CSE students or IT professionals. Also, In this section, we try to explain a topic in a very deep way.