The execution of a function--passing by value

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.