80 Answers
New Answer4/1/2020 6:33:37 PM
Rohit Upadhyay80 Answers
New AnswerThe result of the program is undefined by Standards, the expression suffers from an issue called "sequence point" which happens when the variable is accessed and modified more than once in an expression. Whatever result you get is compiler specific. Search net for more information on "sequence point".
It is compiler dependent. But if u run it in gcc output will be 3 2 3 If u try to figure out how it come U have know the basics of assembly language.
Please read the last para of my comment. The result are compiler specific.
Output is undefined by standards.. Means it give different outputs on different compilers.. compiler specific. See this for explanation... https://www.sololearn.com/Discuss/2038766/?ref=app
Jayakrishna🇮🇳 Please read my answer again at the linked post. This undefined behavior thing is tricky one. I have updated my answer completely. I now believe my new answer is more complete/correct.
~ swim ~ I checked that code on that linked post when I answered there but I was not sure after seeing there your and another previous replies. So I just mentioned in java and added about c++ later so just relate to c++..... Edit: Here I just added link for alternative explanations.. I have only one that. I thought to add more, but stopped after seeing your reply.. Not answered more.. I thought to delete also, because you added enough explanation... All fine now..?
Jayakrishna🇮🇳 Yeah you are right, i was probably thinking too much :) I'll update it but it does produce sequence point (writing it that way). Rest of the explantion needs no more changes :)
Well since the same output is called more than once , u get errors that says : variable a may be undefined. If u try it on another compiler maybe u don't get errors .
printf("%d",a); printf("%d",a++); printf("%d",++a); this way output is 1 1 3 but when we write in this way printf("%d %d %d",a,a++,++a); OUTPUT 3 2 3 this way lead to" sequence point" problem as mansioned before
Sololearn Inc.
535 Mission Street, Suite 1591Send us a message