+ 5
Please explain me.... How the answer came?
a=1; printf("%d %d %d", a, ++a, a++) ; Answer is : 3 3 1 Please explain how it came....
6 Answers
+ 7
There is nothing to explain. Your output is not the definitive one, output relies solely on compiler implementation. That is, you can test and observe such expression in different compiler, and you will get different output between compilers.
Tips:
- Avoid any attempt to mix accessing and modifying a data within a single execution sequence. The standards does not specify how compiler should do this sequentially, you can expect different results from different compiler.
- https://en.m.wikipedia.org/wiki/Sequence_point
+ 5
Just in this case the values are added from right to left but in general there is no single order of evaluation by the compiler for such statements, it might give you different results at times. The order is random. In your case a++ is done first then ++a and then a.
The order of printing the values varies is all I'm saying.
+ 3
Avinesh can u explain?
+ 2
Evaluate from right to left.
+ 2
Similar question: https://www.sololearn.com/Discuss/1969771/?ref=app