c - What is the effect of x=x++;? -
this question has answer here:
#include <stdio.h> int main() { int x=100; x=x++; printf("x : %d\n",x); //prints 101 return 0; }
what reason output 101? think output should 100.
this undefined behaviour, due sequence points.
between consecutive "sequence points" object's value can modified once expression
the end of previous epxression x=100;
1 sequence point, , end of x=x++;
another.
basically, expression has no intermediate 'sequence points', yet you're modifying value of x twice. result of undefined behaviour: basically, anything happen: 100, 101 or 42...
Comments
Post a Comment