-2

code:

#include <stdio.h>

int main()
{
    int i = 2;
    printf("%d%d%d\n", i*=2, ++i, i++);
    return 0;
}

output:

882

Why the second number is 8

1 Answers1

0

The output is undefined behaviour. There's no answer to this question. Arguments can be evaluated in any order and using pre and post-increment operators in the same expression is asking for trouble.

In other words, that output is arbitrary because you can't depend on those behaviours.

tadman
  • 208,517
  • 23
  • 234
  • 262