C
Programming and Technical
undefined
int c,a=2;
c=++a + ++a;
printf("%d",c);
Read Solution (Total 21)
-
- a=2;
Now, 1st pre increment gives ++a=> a=a+1=2+1=3; 2nd pre increment gives ++a=> a=a+1=3+1=4
So, we'll get the final value of a=4
Now, c= ++a + ++a means, c=4+4
So, c=8 (Ans). - 8 years agoHelpfull: Yes(21) No(10)
- 7 because a=2 it perform preincriment operation So a=3 and again pre incriment so a=4 the add so Answer is 7
- 8 years agoHelpfull: Yes(6) No(7)
- a=2, then for 1st ++a = 3 tthen for second ++a=4
c=3+4=7 - 8 years agoHelpfull: Yes(5) No(2)
- 8 is the o/p
- 8 years agoHelpfull: Yes(4) No(2)
- 8 is the required answer
++a pre increment operator will have higher preference than = operator.
So a will get incremented twice and stored in the memory location as 4
so now the value will be picked up from the memory location and c will be calculated as 4 + 4 =8 - 8 years agoHelpfull: Yes(4) No(2)
- 4 Will Be The Answer Since Preincrement Is Included
- 8 years agoHelpfull: Yes(3) No(9)
- ++a=3 so it's referred to + operator 3
and again now the value of a is 3
it's again incremented by 1 so the value of lateral ++a is 4 it refers the 4 to the + operator so
3 + 4= 7
7 is the correct answer - 8 years agoHelpfull: Yes(2) No(0)
- assian the a value is 2
thea above experssion pre increment
c=4+3=7 - 8 years agoHelpfull: Yes(1) No(0)
- a=2;
++a=3
++a=4
++a+++a=8
if a=3;
then
++a=4
++a=5
++a+++a=10 - 6 years agoHelpfull: Yes(1) No(1)
- 3 will be its answer.
- 8 years agoHelpfull: Yes(0) No(5)
- 8 first all the pre increments are done hence a becomes 4
now c=4+4=8 - 8 years agoHelpfull: Yes(0) No(1)
- @baishali roy
Could you explain the same with one more increment.i .e
c=++a + ++a + ++a; - 8 years agoHelpfull: Yes(0) No(1)
- a=2
++a=3
then c=3+3=6 - 8 years agoHelpfull: Yes(0) No(2)
- answer may be 7 and may be 8. its depend on compiler that how the preincremented value is going to store. so explanation of baishali roy and harsh gupra, both are right.
- 8 years agoHelpfull: Yes(0) No(0)
- Final output will be 8 as in this program "volatile" keyword is not used so there will be compiler optimization. If we use volatile int then the output would be 7. try this
- 7 years agoHelpfull: Yes(0) No(0)
- The final answer is 8.
- 7 years agoHelpfull: Yes(0) No(0)
- @balaram achuri-
the increment operator ++a is 3 times so the final value of a is 5 which is then added as 5+5+5=15 and then assigned to c - 7 years agoHelpfull: Yes(0) No(0)
- In a first ++a I.e(3) will assign and after that ++2 I.e(4) will assign and in expression all will sum so answer like
C=3+4, c=7 - 7 years agoHelpfull: Yes(0) No(1)
- 7 is ans
It is pre increment so it is incremented to 3 and then again incremented to 4....so 3+4 is 7 - 7 years agoHelpfull: Yes(0) No(0)
- 6
++a=3;a++=3
c=6 - 7 years agoHelpfull: Yes(0) No(0)
- given a=++a means a=a+1 it is pre increment so we can add first then a=2+1=3
now a=2 . again ++a then a=a+1 it is also a pre increment so a=a+1 a=3+1=4
coming to the question c= ++a + ++a c=4+4 =8
finally c=8 - 5 years agoHelpfull: Yes(0) No(0)
C Other Question