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.