-4

Consider the following code-snippet in C:

int v = 10;
int z = v;
v = v++ + ++v;
printf("v = %d\n",v); // gives 23
printf("z = %d\n",z++ + ++z); // gives 22

Why does this happen?

J. Steen
  • 15,470
  • 15
  • 56
  • 63

1 Answers1

0

Because of undefined behavior, missing sequence point.

unwind
  • 391,730
  • 64
  • 469
  • 606