C
Programming and Technical
Programming
Output
What will be the output of the following C program?
#include
void main(void)
{
int a=5, b, c,d,e;
e= (b=++a) + (c=a++) + (d=++a) ;
printf("%d, %d, %d, %d, %d", a,b,c,d,e);
return 0;
}
[1] 4, 5, 2, 3
[2] 8, 6, 7, 1
[3] 4, 6, 9, 2
[4] 8, 6, 6, 7
Read Solution (Total 13)
-
- a=8
b=6// (b=++a)-here since it is pre increment it gets incremented first and value 6 will be stored in b and a
c=6//(c=a++)-here it is a post increment,the value of a i.e,6 will be stored in c and later a gets incremented to 7
d=8//(d=++a)-as it pre increment,the value of a gets incremented to 8 first and it is stored in both a and d
e=20//adding b+c+d=6+6+8=20 values gives 20 as the final answer
- 8 years agoHelpfull: Yes(4) No(0)
- a=5
b=++a=1+5=6// a=6;
c=a++=a+1//c=6+1; a=6 remain same value
d=++a//d=1+a=1+6=7
after process a=8;b=6;c=7;d=8;e=1; - 8 years agoHelpfull: Yes(2) No(4)
- The ans is 8 6 6 7 19,
Because Firstly pre increment a =6, then a becomes 7 bt displayed as c=6 and again pre so it becomes 8 bt d=7 - 8 years agoHelpfull: Yes(1) No(1)
- ans is 8,6,6,8,20
- 8 years agoHelpfull: Yes(1) No(0)
- answer is a =8, b =6, c = 6, d = 8, e =20
becos b = ++ a i.e a = 6
c = a++ i.e a = 6 after that its value would be incremented to 7
d = ++ a i.e 7+1 = 8
hence e = 20.
- 8 years agoHelpfull: Yes(1) No(0)
- a=5
b=++a=1+5=6// a=6
c=a++=6//a=7
d=++a=1+7//a=8
e=b+c+d=6+6+8=20 - 8 years agoHelpfull: Yes(0) No(0)
- ans is:a=5
b=6
c=6
d=7
e=19
but in printf statement no need of giving (,)
- 8 years agoHelpfull: Yes(0) No(0)
- vandana can u please elaborate?
- 8 years agoHelpfull: Yes(0) No(0)
- a=5
e=6+6+8
e=20
b=6
c=6
d=8
- 8 years agoHelpfull: Yes(0) No(0)
- unsolved because we cant perform addition
- 8 years agoHelpfull: Yes(0) No(0)
- 8,6,6,7,19
- 8 years agoHelpfull: Yes(0) No(0)
- The correct answer would be 8,6,6,8,20
- 8 years agoHelpfull: Yes(0) No(0)
- a=5 given
b=++a
that means b=5+1=6 and a=6
c=a++
that means c=6 and a=7
d=++a
which means d=7+1=8 and a=8
and now a's current value is 8
therefore
a=8 b=6 c=6 d=8 e=20 - 8 years agoHelpfull: Yes(0) No(0)
C Other Question