0
#include<stdio.h>

int main(){
    int a =3;
    printf("%d %d %d %d %d",++a,--a,a++,++a,++a);
}

It prints the result -

4 4 3 4 4

Can anyone please explain?

  • The order of evaluation of arguments to a function is unspecified. There are 120 possible ways that the code could evaluate those arguments, and no basis for expecting any one of them. – Pete Becker Apr 17 '21 at 15:49
  • Despite the linked answer in the close votes, the behavior here is not undefined. It is unspecified; the code is valid, but the compiler is free to evaluate the five arguments in any order. – Pete Becker Apr 17 '21 at 15:50
  • It’s undefined behaviour. There is no sequence point between evaluation of arguments. Actually, the compiler is free to mix evaluations if the arguments. – gnasher729 Apr 17 '21 at 16:55

0 Answers0