Can anyone explain how the output has come? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 12

Can anyone explain how the output has come?

When I do the 5 parts of the code separately I am getting output as 5 3 3 4 5 But when I combine all in one line it is giving output as 6 5 6 5 5 Can anybody explain why? https://code.sololearn.com/caL98lUPp1w3/?ref=app

30th May 2020, 6:44 AM
Puthur Harthik
6 Answers
+ 10
Avinesh so you telling that there is no reason for the output to come as so. and I also want to tell you that the question I posted is a bit different from the question about which you are talking of. I asked to print value after each increment/decrement.
30th May 2020, 9:06 AM
Puthur Harthik
+ 8
Avinesh I saw these posts but didn't get the answer for the second part of code. Could you please explain.
30th May 2020, 7:43 AM
Puthur Harthik
+ 5
You can read the compiler warning, it is an undefined behaviour. It is discussed here. https://www.sololearn.com/Discuss/2284550/?ref=app https://www.sololearn.com/discuss/2111410/?ref=app
30th May 2020, 6:57 AM
Avinesh
Avinesh - avatar
+ 4
Its depend on compiler how compiler its calculate. i tried in three different compiler am getting different output .
31st May 2020, 10:52 AM
A S Raghuvanshi
A S Raghuvanshi - avatar
30th May 2020, 9:08 AM
Avinesh
Avinesh - avatar
+ 1
Puthur Harthik Read from the 2nd thread that I shared. The order of evaluation is not so well defined in C and C++ unlike other languages like java etc.
30th May 2020, 8:39 AM
Avinesh
Avinesh - avatar