1. What are left and right values?
The left value is the value that appears to the left of the expression (the left side of the equals sign) and can be changed, which is the address of the memory that stores the data value, also known as the variable's address;
The right value refers to the data stored in a memory address, also known as a variable.
The lvalue can be the right value, but the right value cannot be an lvalue.
Therefore only the left value can be taken to address.
2. To raise two questions:
int i = 0;
(i++) +=i; Error
(++i) +=i; That's right
int *ip = & (i++); Error
int *ip = & (++i); That's right
3, why i++ can not be left value?
We see the realization of i++ and i++.
The prefix form:int& int::operator++ ()//is returned here is a reference form, that is, the function return value can also be used as an lvalue to use the {//function itself without parameters, which means to add 1 of the *this + + 1 in its own space; Add return *this; Retrieve value}
Suffix form: const int int::operator++ (int)//function return value is a non-lvalue type, which differs from the prefix form. {//function with parameter, indicating there is another space to open int oldValue = *this; Fetch value + + (*this); Add return oldValue; Returns the retrieved value}
Simply understood, is that i++ returns a temporary variable that cannot be addressed after the function is returned, it is just a data value, not an address, and therefore cannot be left-valued.
A simpler code explanation:
I++:{int Tmp;tmp=i;i=i+1;return tmp;} ++i:{i=i+1;return i;}
Reference article:
http://blog.csdn.net/zlhy_/article/details/8349300
(c + +) Lvalue, rvalue issues for i++ and i++