Yao Brothers yesterday when asked to quote, there was a little bit of an ignorant. Usually used in the reference time is the function of the parameter passing.
A reference is an alias for a variable, and the operation of the reference is exactly the same as for a variable, but it is important to note that the reference does not have a new memory space and therefore does not account for the inner deposit element. When declaring a reference, it must be initialized at the same time.
To simply understand the reference, write the following code:
intA =Ten; intb = -; Std::cout<<"a"<< &a <<Std::endl; Std::cout<<"b"<< &b <<Std::endl; Std::cout<<"________________________"<<Std::endl; int&c=A; Std::cout<<"a"<< &a <<Std::endl; Std::cout<<"b"<< &b <<Std::endl; Std::cout<<"C"<< &c <<Std::endl; Std::cout<<"________________________"<<Std::endl; C=b; Std::cout<<"a"<< &a <<Std::endl; Std::cout<<"b"<< &b <<Std::endl; Std::cout<<"C"<< &c <<Std::endl; Std::cout<<"________________________"<< Std::endl;
The result of the code operation is as follows:
However, in the previous debugs, when the code went to "C=B;" , you see that the value of A,b,c is 20. The small head is a bit chaotic, and once thought that the variable C is also a reference to the variables A and B. It is known that after the reference is initialized, it is no longer possible to alias the reference as another variable. At one point it was c++11 that the rules had been revised, and had specifically checked the official documents of C++11. Almost did not respond to come over. Think carefully, the original "C=B;" Instead of modifying the alias, it is simply a simple shaping assignment that is logically equivalent to "c= 20", and the code above is written to validate the idea. It turns out that the address of the variable C is the same as the variable a address, and does not change its address after "C=B;" is executed.
References to C + + variables