Last blog I probably introduced the origin of the function and the execution of the function, next, I want to explain the function at the time of execution of the arguments passed-by value.
First use C + + to write a function for everyone, the function is to compare the size of two numbers. Then the function parameters in the stack of the transfer process I will give you a picture.
<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" > #include <iostream>using namespace std;int max (int x, int y) { int z; z = (x>y)? x:y; return z;} void Main () { int A, b; cin>>a>>b;//Enter the two number Cout<<max (A, B) Endl that will be the size of the comparison ;} </span>
as we can see from the previous blog, the function call procedure actually performs a parameter pass----> executes the function body----> return procedure, where the essence of the function parameter passing is the process of passing the argument value through the stack control one by one to the formal parameter. This transfer of the value of an argument expression to a corresponding form parametric is called "Pass by Value".
Let's put a picture of the stack memory and executing code memory in the function execution process.
In this picture the push () is called the stack, pop () is called to make the stack, the data in the stack, advanced and out. In combination with this image, we can understand how memory is a function "service" in the process of function call.
Third, summary
The value call is called by a call to the name. When a value is called, the argument assigns only its value to the parameter, so the value of the parameter in the function, regardless of whether we modify it, does not affect the value of the argument.
The execution of a function--passing by value