#include <stdio.h>
int main()
{
int x=5, y;
y=x+++x;
printf("%d", x);
printf("%d", y);
}
What I found is that postfix increment has higher precedence than prefix.
Hence
y=x+++x;
y=(x++)+x;
y=10
x=6
But when I execute the program :y=11,x=6
Please correct me if I am understanding anything wrong
Splitting it down and remembering that there is also the "right-left rule" This is a simple rule that allows you to interpret any declaration. It runs as follows:
So, parsing Right-to-Left in the absence of parentheses:
x=5
, so using the prefix operator++x
increments the value beforey
is assigned.Then an assignment is made to
y
equivalent to5+6
(i.e.x+(++x)
)x
was incremented, sox=6