+ 5
Any one guess the output and how ??
a=1 Printf("%d %d %d",a,a++,++a)
80 Answers
+ 2
Its right...but how can u get this ??
+ 5
1
2
3
+ 3
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.
+ 2
Okk thanxx dude...
+ 2
The output is 3 2 3
+ 2
Output is 3 2 3
+ 2
Answer would be 1,2,2
+ 2
It depends on compiler.
+ 1
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
+ 1
It print 3 2 3
+ 1
~ 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..?
+ 1
I don't understand please help me
+ 1
it print 1 1 3
+ 1
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
+ 1
3 2 2 is the correct answer
+ 1
Language problem
+ 1
I tried in different two compilers in solo its giving 323 but in other 113 . Its a languages dependent . In cpp output is 113
+ 1
113
+ 1
See printf() uses stack. Means your last argument is treated first then 2nd last argument at second place…. first argument is treated at last.
Step 1: last argument is treated first. ++a becomes 2 but that last is not assigned value of 2 yet. It’s waiting for whole statement to execute then assign value. Yet we get value of a as 2
Step 2: Now its time to treat 2nd or I can say 2nd last argument. Told you post increment instantly assigns value then do increment operation. So 2nd argument gets value assigned to 2. Increment is now done and value of a turns out to be 3.
Step 3: Now its time to treat the first argument. It simply gets value assigned 3. Now that all the operations are performed so it’s time for pre-increment to do its left out work(assignment of value). So last argument gets value of 3.
So answer of your query is : 3 2 3
And one more thing to remember:The answer may vary compiler to compiler. Many compiler have different implementations of printf().
+ 1
its printing 3 2 3.I think it first starts with ++a and a=2, then it goes to a++ and a=3 but post increment return values befor expression so a++ is 2 and ++a and a returns 3 after all updates.