Contact Us || Privacy Policy || About Us |
|
Call by Value and Call by Reference in C++There are two types of function are available in C++ ![]() Call by ValueIn call by value, when you have passed the value to the function it is locally stored by the function parameter in stack memory location.If you change the value of function in parameter, it is changed for the current function only, but it not change the value of variable inside the caller function such as main(). Original value can not be modified. Output: Value of a: 200 Value of b: 100 Call by referenceIn call by reference, original value is changed or modified because we pass the reference (address). Here, address of the value is passed in the function, so actual and formal arguments shares the same address space.Hence, value changed inside the function, is reflected inside as well as outside the function. Output: Value of a: 200 Value of b: 100 Difference between call by value and call by reference.
|