Consider the Following Code:
/ / ================================== 1 int Max (int & n1, int in) 2 {3 if (N1> N2) 4 RETURN N1; 5 else6 Return N2; 7}
8 void main () 9 {10 int x = 1, y = 2; 11 max (x, y) = 5;} // ===================== ================
The Can Not Be Complier. Because in line 11, a value is returned Which is a const. A const cannot be assigned a new value.
However, if we changed the code in line1 toint & max (int & n1, int & n2) The code can be complied and exectuted! Because a reference has been returned, which is either x or y in the main function. That is, returend reference is A variable. assign a value to a variable is legal.