In-address delivery, the reference parameter is a reference to the argument variable, as mentioned before, the reference is just the equivalent of an alias, the system will not allocate storage space for it, so at this time, the function changes the parameters, the actual parameter values will change accordingly. Passing by value simply passes the value of the argument to the parameter variable, participates in the operation, because it is in a different storage unit, so the argument value is not affected.
Value passing (passed by value) 1. The argument value is passed to the corresponding parameter 2. The argument address is passed to the corresponding parameter, such as an array, a pointer.
Address delivery (reference passing) uses aliases, where the shared storage space (direct access) parameter is referred to as a reference, and the argument is generally a variable.
For example:
int func (int *p,int *q) {}
void Main ()
{
int a,b func (&a,&b);
}
In the main function, the storage space of the variable a,b is opened up, when the Func function is executed, the system will open up the storage space needed for the p,q, except that P and Q point to A,b respectively. Therefore, the argument is passed the address value to the formal parameter, or it is passed by value. If the program changes to this (reference call):
int func (int &p,int &q) {}
void Main ()
{
int a,b func (a,b);
}
In main function, the storage space of variable a,b is opened up, when the Func function is executed, the system does not open up storage space for p,q, but uses the storage space of real parameter a,b. Therefore, the combination of the actual situation, the formal parameter part does not open up storage space.
The value of the function's parameter itself is unchanged before and after the call, and any modifications made within the function body have no effect on the value outside the function. Even if the pointer is passed, in essence, C + + also made a copy of the pointer to a copy of the pass to the function.
In the case of passing the pointer, the modified is not the value of the pointer parameter, but the value of the space to which the pointer parameter is pointing. The first question: pointer pass: belong to pass by value.