I have a problem with C# operator precedence.
I've read in the docs that postfix increment (x++
) has higher precedence than prefix increment (++x
), so in this code the result must be 2 but it shows 0.
int x = 10;
int y = ++x - x++;
First x++
executes so we have:
// x = 11;
int y = ++x - 10;
and then ++x
executes and we have:
// x = 12;
int y = 12 - 10;
But it shows the result 0.
i read that the left side of - must evaluate first but - has lower precedence than x++.
please don't refer to another topic.
explain this specific example
What is going on?