C
Programming and Technical
Programming
Program
what is the output of the following piece of code :-
#include
int main()
{
int a = 5;
printf("%d %d %d",++a,a,a++);
return 0;
}
Read Solution (Total 27)
-
- output is 7,6,5
because (,) operator works right to left
so first evalute a++ which is post increment so value remains 5.
and after that a=6
++a=7. - 10 years agoHelpfull: Yes(15) No(2)
- 6,6,6 Declaring 'a' variable as 5 so ++a means pre-increment of 'a' then 'a' will become a=6,then print a means current 'a' value is 6,then 'a' will be post incremented after perform operation it goes to increment so.., it first print the current value of 'a' and then increment 'a' value
- 10 years agoHelpfull: Yes(8) No(2)
- 7,7,5
in this program we have to come from rigth to left.... - 10 years agoHelpfull: Yes(5) No(4)
- in gcc compilers
++a,a,a++
7 6 5
the pre-increment changes 6 to 7 as a's value has been updated so output is:
7 7 5
turbo c compiler
output is: 7 6 5
the compiler doesn't update the value of a - 10 years agoHelpfull: Yes(5) No(0)
- ++ operator are working in right to left order. but after perform the operation stor in stack.to output in lifo methode.
so s1: a++=5,a=6 store
s2:a=6.
s3:++a=7
print order:s3,s2,s1.
output:765
- 10 years agoHelpfull: Yes(4) No(2)
- 6 6 6
++a means PreIncrementation so the value of a will become 6
Now current value of a is 6
again a++ means the value will remain same because a++ post increment.
- 10 years agoHelpfull: Yes(2) No(2)
- result is 6,6,6
- 10 years agoHelpfull: Yes(2) No(3)
- the output will be 7,7,5.....
- 10 years agoHelpfull: Yes(2) No(2)
- 765 because it works form right to left.
- 10 years agoHelpfull: Yes(1) No(1)
- 6 5 5
in ++a it will increment so we get 5+1=6
in a we get as it is 5
in a++ 5 will be assigned then it will increment
so final answer is 6 5 5 - 10 years agoHelpfull: Yes(1) No(0)
- Output 5,5,6
As ++a is a preincrement operator and a++ is post increment operator.
- 10 years agoHelpfull: Yes(0) No(2)
- a=5
++a=>pre increment=>5 first increments and that increased value is stored in a =>5+1=6
a++=>post increment=>5 is stored in a and then it increments by 1
so output is 6&5. - 10 years agoHelpfull: Yes(0) No(1)
- printf works from left to right.so
I st a++ will operate.
a++=>5 is stored & increments by 1.
now a=6
++a=>7.
so,output is 7,6,5.
- 10 years agoHelpfull: Yes(0) No(1)
- It is a compiler dependent, But this is procedure is for Turbo c++ compiler
Actually in printing the statement block, In case of printing a datatype it is designed to execute it in reverse order(it is same in GCC compiler even)
So the output is 7 6 5 - 10 years agoHelpfull: Yes(0) No(1)
- given a=5,++a=6,a=6& a++=6
- 10 years agoHelpfull: Yes(0) No(0)
- Output is 7,6,5
because of stack property of c program - 10 years agoHelpfull: Yes(0) No(0)
- a=5; =7,6,5
- 10 years agoHelpfull: Yes(0) No(0)
- sorry usually ,(comma) works from left to right hence the solution will be
6,6,7 - 10 years agoHelpfull: Yes(0) No(1)
- 7 6 5
exe:l to r
print :r to l
- 10 years agoHelpfull: Yes(0) No(0)
- in this program printf() evaluation take place from right to left. so when a++ execute then first value of 'a' store in program stack then post inc take place ,then after when move to next 'a' become 6 and store in stack,after that when we came to ++a then first pre inc then store value in stack .then after print value of a from stack one by one.
ANS:-765 - 10 years agoHelpfull: Yes(0) No(0)
- 765 because ++ operator works from right to left
- 10 years agoHelpfull: Yes(0) No(0)
- printf("%d %d %d",++a,a,a++);
execution start from left to right
so a++ is post increment ans is 5
then a is 6
then ++a is 7
so finally it will print 7 6 5 - 10 years agoHelpfull: Yes(0) No(0)
- ++a---- a value become 6
then a++-- a value will incremented but it is done after completing of printf statement.
so answer is 6 6 6.
- 10 years agoHelpfull: Yes(0) No(0)
- ++a=6 a=6 a++=6
- 10 years agoHelpfull: Yes(0) No(0)
- coming from right to left
a++ remains 5
in memory a stores 6
++a incremented to 7
ans will be 7 6 5 - 10 years agoHelpfull: Yes(0) No(0)
- 7,7,5
increment will have more precedence than normal variable so compiler compiles a++ first as 5 then ++a as 7 and stores final value of into a=7
- 10 years agoHelpfull: Yes(0) No(0)
- since der are multiple number of %d of same variable in printf statement evaluation starts from right so the right answer is 5,6,7
- 9 years agoHelpfull: Yes(0) No(0)
C Other Question