c++ – Why is ++i considered an lvalue and i++ an rvalue?

Question:

Why is ++i considered an lvalue and i++ an rvalue?
I found the answer to this question on stackoverflow , but my terrible English does not allow me to understand it competently. After all, the priority of prefix and postfix ++ is still higher than & , and in theory, in any case, it will be ++ first, and only then & , or am I not understanding at all?

Answer:

Perhaps this is a very incomplete answer compared to the expanded first one in the link, but the gist is this:

The postfix operator changes a value and returns only a temporary copy of that value, which, as a result, cannot be changed. That is, this copy is separate from the i value itself, and can be used in an expression, but the assignment to i++ does not make sense, because the result of i++ is stored in some other memory location, not in the one where i is located.

The result of ++i is written to it, so the expression ++i = ... makes sense (l-value).

Scroll to Top