Consider this code:
int x = 99;
int * p = &x;
*p = *p + 1;
Why do the *p
on the left side and right side of the =
operator differ?
How does the compiler know to use the left *p
to be the object x
and the right *p
to be the value of x
?
Specifically, if the compiler evaluates *p
to be the value of x
, why does the *p
on the left side not evaluate to 99, creating an erroneous assignment to a literal: 99 = 99 + 1;
?
Similarly, if the compiler evalues *p
to be the object x
(assuming that that is what the left operand of the =
operator expects), why does not the *p
on the right hand side also evaluate to the object x
?