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??
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