Call by Value in C Functions

Last Updated Nov 20, 2015, 07:00:14 PM





In call by value mechanism, the called function creates a new set of variables in stack and copies the values of the arguments into them

Call by Value

In call by value mechanism, the called function creates a new set of variables in stack and copies the values of the arguments into them

Changes made to the parameter inside the function have no effect on the argument

call by value

Example Try It Now

How Call by Value Works?

In the call by value mechanism, we pass the parameters to the function using call by value, during that a time a sample copy of original parameters will be created and passed to the called function

Any changes made to the original values does not effect the copied parameters, meaning any changes made inside the function does not effect the original values of calling function

In the above example, if you notice, the new_num1, new_num2 are the original values and a copy of these values are passed to the function and these values are copied into n1,n2



Some interesting online threads about this topic, it might help you learn more

What is the difference between call by value and call by reference in C? - Quora

Difference Between Call By Reference And Call By Pointer? - StackOverFlow

Other function Topics you might want to learn

functions in c

Call by Reference