0

C programming increment operator related

int a=3; int b=++a + a++; printf("%d",b); gives output 9 whereas int a; scanf("%d",&a); int b=++a + a++; printf("%d",b); gives output 8 for a=3 Why??

22nd Sep 2018, 9:27 AM
MR. HACKER
MR. HACKER - avatar
1 Answer
+ 6
The produced answers are undefined behaviors Âč. The code is violating the sequencing rule ÂČ by using the increment operator Âł , carelessly. ____ Âč https://en.wikipedia.org/wiki/Undefined_behavior ÂČ https://en.wikipedia.org/wiki/Sequence_point#Sequence_points_in_C_and_C++ Âł https://en.cppreference.com/w/c/language/operator_incdec
22nd Sep 2018, 11:06 AM
Babak
Babak - avatar