Possible Duplicate:
Undefined, unspecified and implementation-defined behavior
Undefined Behavior and Sequence Points
Pre & post increment operator behavior in C, C++, Java, & C#
I have this code-snippet:
int x = 2;
int y = x + 4 * ++x;
// what is y???
And when I compile and test it in c/c++ I'll get:
// C/C++
y is 15
But via c# I'll get
// C#
y is 14
WHY?
A part of IL is:
locals init ([0] int32 x,
[1] int32 y)
IL_0000: nop
IL_0001: ldc.i4.2
IL_0002: stloc.0
IL_0003: ldloc.0
IL_0004: ldc.i4.4
IL_0005: ldloc.0
IL_0006: ldc.i4.1
IL_0007: add
IL_0008: dup
IL_0009: stloc.0
IL_000a: mul
IL_000b: add
IL_000c: stloc.1
IL_000d: ldloca.s y