[C / C ++ function calls] on passing arguments

Function calls two approaches arguments:

#include <bits / STDC ++ H.>
 the using  namespace STD; 
typedef struct 
{ 
    int * elem; // the base address of the memory space, so the need to allocate memory for use, as shown in the following two functions, when written as elem [20] is not in the form of an array. 
    int len; 
} Node; 
void AAA (Node * Ll) 
{ 
    ( * Ll) = .elem new new  int [ 20 is ];
     for ( int I = 0 ; I < . 4 ; I ++ ) 
        CIN >> (* Ll) .elem [ I]; 
} 
void BBB (Node & L2) // & reference type declaration List2 L2 is a reference, and modifying the operation of L2 is directly modified List2
{ 
    L2.elem = new new  int [ 20 is ];
     for ( int I = 0 ; I < . 4 ; I ++ ) 
        CIN >> L2.elem [I]; 
} 
int main () 
{ 
    Node the List1, the List2; 

    / * function delivery solid reference practice 1: transfer address * / 
    AAA ( & the List1); // & fetch address is a character 
    for ( int I = 0 ; I < . 4 ; I ++ ) 
        COUT << List1.elem [I] << '  ' ; 
    COUT << endl;

    / * Function arguments passed approach 2: reference transmission * / 
    BBB (the List2); 
    for ( int I = 0 ; I < . 4 ; I ++ ) 
        COUT << List2.elem [I] << '  ' ; 
    COUT << endl; 
}

 supplement:

= 5 x int;
int & * y = x; // pointer for transmission, y has its own memory address, the address is stored contents of x * y is the value of x * y that is equal to 5.
int & z = x; // for transmitting reference, is to make z of x becomes the alias, a modification of any other of these values will change.

Guess you like

Origin www.cnblogs.com/HOLLAY/p/11567117.html