Further analysis of the difference between reference parameters and value-passing parameters

Source: Internet
Author: User
Tags constant
The following is a detailed analysis of the difference between the reference parameter and the value-passing parameter, the need of friends can come to refer to the next

1. As we all know, the ordinary parameter is passed to the argument by the argument;

The compiler generates a temporary variable for each parameter within the function, presses each parameter into the stack (stack), and saves the value of the argument to a temporary variable.

So only in the low-end 8-bit machine, the number of parameters are more stringent restrictions, because the depth of the stack is very limited; Of course, in the general machine also have the same problem, too many parameters are not suitable, but the depth of the general machine stack more than low-end machine;

2. The address of the variable to be passed by reference parameter;

A pointer to a variable is essentially passed;

The advantage of referencing as a parameter is that it reduces the overhead of a temporary variable for memory and is therefore often used for operations on large objects;

And often cited as a parameter is to protect the parameters are not modified;

Attachment: Knowledge of heaps and stacks
the memory used by a program compiled by C + + is divided into the following sections

1, stack area (stack)-by the compiler automatically assigned to release, store the function of the parameter values, local variables, and so on. The operation is similar to the stack in the data structure.

2, heap area (heap)-Generally by the programmer assigned to release, if the programmer does not release, the program at the end may be reclaimed by the OS. Note that it is different from the heap in the data structure, the distribution is similar to the list, hehe.

3, the global area (static)-------------------------------------------------------------- -System release after the program is finished

4, literal constant area-the constant string is here. Released by system after program is finished

5, program code area-the binary code that holds the function body.

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.