Value transfer method:
1. Common call. The real parameters involved in the form are of the same type.
Fun (int I )()
Fun (student stud)
()
Main ()
{
Fun (1 );
Student S1;
Fun1 (S1 );
}
You can modify the value of a parameter in a function, but cannot change the value of the corresponding real parameter (the value change of the parameter cannot be transferred to the real parameter: during function calling, a new object is created, which is a copy of the real parameter object. The real participating parameters occupy different storage spaces. no matter whether the parameters are modified or not, the value of the real parameter is not changed. In this form, the combination of real and false will generate a copy of the real parameters. When the transferred object is large, both the time overhead and the space overhead are large.
2. Use pointers as function parameters
Fun (int * I)
{}
Fun (student * stud)
{}
Main ()
{
Int I = 1;
Fun (& I );
Student S1;
Fun1 (& S1 );
}
The essence is also the value transfer method, but the passed value is an address. The real parameter passes the address to the form parameter. After the actual parameter is combined with the actual parameter, the real participation parameter points to the same address. It operates on the same object. When combined with real-world, a copy of the real parameters will also be generated, allocating memory for the shape parameters, used to store the pointer value (that is, the address)
2. Reference Transfer Method
1. Use reference as function parameter
Fun (Int & I ){}
Fun (student & stud ){}
Main ()
{
Int I = 1;
Fun (I );
Student S1;
Fun1 (S1 );
}
Instead of allocating storage space for parameters (often called a copy of a created real parameter), it passes the address of the real parameter to the parameter (reference name), and the reference name also points to the real Parameter Variable