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 ответ
+ 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