-4

can you please explain me this.

I have read almost all questions on stackoverflow

    1. undefined behaviour
    1. pre/post inc.. dec.. operator precedence/associativity
    1. use the parenthesis

but results are inconclusive.

please explain this i have an interview tomorrow.

int a, x = 0;
//                               value of x ------>                 a(sum)      
//gcc 4.9.9.2[dev cpp]            2    1      2      4      5       14
//acc to my calculation           2    0      2      4      5       13      
//geeksforgeeks compiler          5    5      5      5      5       15
//gcc 6.3 [codechef ide]          5    5      5      5      5       15
a = ((((++x + x++) + ++x) + ++x) + ++x);

printf("%d....%d", x, a);

return 0;

if i have made mistake please help me to correct them. Thanks

MD XF
  • 7,860
  • 7
  • 40
  • 71

1 Answers1

2

There is no sequence point, thus your code invokes Undefined Behavior.

Parentheses do not introduce sequence points, thus, despite the fact that you use them, you still invoke UB.

gsamaras
  • 71,951
  • 46
  • 188
  • 305