0

Can anyone please explain this?

I=10; printf("%d%d%d",i,i++,i--); o/p is 10910 why?

23rd Mar 2018, 5:06 AM
Akhil Sai
Akhil Sai - avatar
4 Answers
+ 13
the %d is replaced by respective double variable. first one is 10, and so goes on...
23rd Mar 2018, 5:21 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 6
This is a classic case of undefined behavior and sequence points in C/C++. https://gist.github.com/gkastrinis/22c27578cfa093837880
23rd Mar 2018, 6:11 AM
David Carroll
David Carroll - avatar
+ 1
The output will be: 101011 This is because the value of i is incremented after the second parameter i.e., i++, but the decrement occurs after print in case of second parameter i.e., i--.
23rd Mar 2018, 5:35 AM
Chitti Prasad V.L.N.
Chitti Prasad V.L.N. - avatar
0
output is 10910
23rd Mar 2018, 5:51 AM
Akhil Sai
Akhil Sai - avatar