Differentiate between call by value and call by reference method.
Call by Value
|
Call by reference
|
In call by value, a copy of actual arguments is passed to respective formal arguments.
|
In call by reference, the location, that is, the address of actual arguments is passed to formal arguments
|
Actual arguments will remain safe, they cannot be modified in the called function.
|
Alteration to actual arguments is possible within called function.
|
Address of the actual and formal arguments are different
|
Address of the actual and formal arguments are the same
|
Changes made inside the function is not reflected in other functions
|
Changes made in the function is reflected outside also.
|
Example: swap(a,b); //function call void swap(int a,int b)// function definition { }
|
Example: swap(&a,&b); //function call void swap(int *a,int *b)// function definition { }
|