#include <iostream>using namespacestd;intMain () {//to alias a variable intA = A; int&c = A;//declare a reference to variable a C, C is an alias for variable A, not the de-address character in the previous section. The same variable can be multiple references. //the declaration must be initialized when it is referenced, and int &d; is not allowed intD = C;//references can continue to be referenced. c = -; cout<< a <<Endl; cout<< &a <<' '<< &c <<' '<< &d << Endl;//The address is exactly the same, fully connected to the same block. System ("Pause"); return 0;}
#include <iostream>using namespace std;
intMain () {//a reference to a constant that does not allow modification after a reference Const int&a = A; cout<< a <<Endl; //references to Arrays intarr[ A]; int(&p) [ A] = arr;//Reference typep[2] = -; cout<< arr[2] <<Endl; intarr2[2][3]; int(&P2) [2][3] =arr2; p2[1][2] =123; cout<< arr2[1][2] <<Endl; //struct Reference type & name = struct instance;//reference to Pointers intx = A; int*point = &x; int* (&y) =Point ; *y = Wu; cout<< *point <<' '<< x <<Endl; System ("Pause"); return 0;}
C + + Learning--Reference variables