I have the same code on visual studio C++ and C# and each compiler has a different output although both have the same precedence and associativity table
On C++
int i = 10;
int a = i++ + ++i + i--;
printf("a=%u\n",a);
i = 10;
a = i++ + i;
printf("a=%u\n",a);
int x=2,y=3;
int z=((x++)*(x++))+((++y)*(++y));
printf("x=%u , y=%u , z=%u \n",x,y,z);
the output is
a=33
a=20
x=4 , y=5 , z=29
On C#
int i = 10;
int a = i++ + ++i + i--;
Console.WriteLine("a={0}",a);
i = 10;
a = i++ + i;
Console.WriteLine("a={0}", a);
int x = 2, y = 3;
int z=((x++)*(x++))+((++y)*(++y));
Console.WriteLine("x={0} , y={1} , z={2}",x,y,z);
the output is
a=34
a=21
x=4 , y=5 , z=26
In C# I found that the operation obey the precedence table that post-increment has a higher precedence that pre-increment and so it places the value then increment I can't find any logical explanation for this . Could anyone explain this ?