Int x = 3; x = ++× + x++ + x++; x = ? Can someone please explain this to me. I get 13 , shouldn't it be 14? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Int x = 3; x = ++× + x++ + x++; x = ? Can someone please explain this to me. I get 13 , shouldn't it be 14?

C language

17th Apr 2020, 8:25 AM
El Cha
4 Answers
+ 4
A decent compiler should show you a warning, telling you that evaluation of <variable-name> may be undefined. The idea of modifying data while accessing it altogether at the same point is no good practice, as the order of modification and access is not defined. Please refer this for more details 👇 https://stackoverflow.com/questions/4176328/undefined-behavior-and-sequence-points
17th Apr 2020, 8:55 AM
Ipang
0
X = ++x + x++ + x++ X = 4 (pre increament) + 4(post inc) + 5(post inc) And if you print x; it would be 6
17th Apr 2020, 8:29 AM
Wasi
Wasi - avatar
0
The compiler gives me 13 !
17th Apr 2020, 8:30 AM
El Cha
0
That is what i said. 4+4+5=13
17th Apr 2020, 8:31 AM
Wasi
Wasi - avatar