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

Question:

Why is ++i considered an lvalue and i++ rvalue?
I found the answer to this question on stackoverflow , but my terrible English does not allow me to correctly figure it out. 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 I don't understand at all?

Answer:

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

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

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

Scroll to Top