++n
Equivalent to n=n+1
, n increments by 1, the result is an lvalue , which can be placed on the left side of the equal sign:
n=1;++n=1;
The result is: n=1
indicating that the result of ++n is returned to n, and then 1 is assigned to n,
n=1;a=++n;
The result is:a=2,n=2
n++
Equivalent to n=n+1
, n increments by 1, but the result is the right value
n=1;n++=1;
Error: error
indicating that the result of n++ cannot be assigned again (downgraded from a variable to a memory value???)
n=1;a=n++;
The result is:, a=1,n=2
indicating that the priority of n++ is lower than a=n;
The difference between left value & right value
(In the assignment statement) The
lvalue indicates that this variable points to an address, can be assigned again, can be overwritten, and remains a variable after assignment.
The rvalue indicates that the variable has been directly stored in a memory space, and the assignment statement can only operate on the variable, not on the memory space (constant?), and cannot be overwritten again.
exception
When n++;
or ++n;
as a separate statement appears, the effect is n=n+1;
no different.
Description
I don't know if the reasons I think are correct, but just understand it like this for the time being, it can deepen the memory and solve a little doubt.
Information:
Understand lvalues and rvalues in C and C++
Baidu knows