Data type & alias = object name;
1#include <iostream>2 using namespacestd;3 4 int* F (int*x)5 {6(*x) + +;7 returnx;8 }9 Ten int& G (int&x) One { AX + +; - returnx; - } the - intx; - - int&h () + { - intQ//!return Q + returnx; A } at - voidMain () - { - intA =0; -Std::cout << a << std::endl;//0 - inf (&a);//ugly, but clear. -Std::cout << a << std::endl;//1 to +g (a);//clear, but covert, can modify a -Std::cout << a << std::endl;//2 the *H () = -;//The return value is a reference, so you can do an lvalue $Std::cout << a << std::endl;//2Panax Notoginseng -Std::cout << x << Std::endl;// - the +System"Pause"); A}
You cannot declare a reference reference
You can declare a reference to a pointer, but you cannot declare a pointer-to-variable reference
int & * P;//illegal
int * & P1=p2;//ok
void f (int * & P);
P is a reference that references a pointer to type int
You can declare a pointer to a reference
Arrays without references (array elements cannot be references)
But you can reference an array
Object-Oriented Programming-c++_ lesson 21 references