When viewing, can you have an increment and decrement in the same variable in the same in c
I found that you can have several increment / decrement prefix operators for one variable, but only one postfix
Example:
++--++foo; // valid foo++--++; // invalid --foo++; // invalid
Why is this?
This is due to the fact that in C ++ (but not in C), the result ++xis the value lValue, that is, it can be assigned and, thus, capable of chaining.
++x
However, the result is x++NOT an lValue, instead it is a prValue, that is, it cannot be assigned and therefore cannot be bound.
x++
++ / lvalues, r. , lvalue. , / , lvalue ( /).
++ ,
int i = 0; int *p = &++i;
i p i. & lvalue-, ++ ( ).
i
p
&
++
/ , , undefined, , , (.. "" ).
++foo-- , ++ postfix , . . , (++foo)-- , undefined .
++foo--
(++foo)--