C
Programming and Technical
Programming
Output
main()
{
int a=10,b;
b=(a++)+(a++);
a=(b++)+(b++);
printf("a=%d and b=%d",a,b);
}
Options
1) a=43 b=21
2) a=42 b=21
3) a=43 b=23
4) a=44 b=20
Read Solution (Total 48)
-
- ans is a=43,b=21
because b=(a++)+(a++) means a++ is post increment so value of a will remain as 10 for first time t 1hen it will increment by 1 so b=10+11=21
same as b=21+22=43 - 10 years agoHelpfull: Yes(29) No(7)
- a=43 and b=23
- 10 years agoHelpfull: Yes(17) No(3)
- b=(a++)+(a++) means that 10+10 = 20 will assign in B then A will be increase two times ....after incrementing A become 12 but again a will be override by (b++) + (b++) means 20+20 =40 will assign in A. now B will be increment two times and B become 22.
- 10 years agoHelpfull: Yes(17) No(9)
- a=21 and b= 43
- 10 years agoHelpfull: Yes(7) No(11)
- b=11+11=22, a=23+23=46
- 10 years agoHelpfull: Yes(6) No(8)
- b=10+10;
now a=12,b=20;
a=20+20;
a=40 b=22; - 10 years agoHelpfull: Yes(5) No(1)
- b=23,a=43
- 10 years agoHelpfull: Yes(4) No(1)
- It gives ans as a=40,b=22
- 10 years agoHelpfull: Yes(3) No(2)
- a=10
b=(a++)+(a++);
=10+11=21 and a=22;
now
a=(b++)+(b++);
=21+22=43 and b=23;
therefore,a=43 and b=23;
because it is postfix operator...value inc after using the presennt value of the variable; - 10 years agoHelpfull: Yes(3) No(0)
- b=20
a=40
a++ is incremented in nextline - 10 years agoHelpfull: Yes(2) No(8)
- b=21
a=43
as a++ means ,first the value is used and then gets incremented - 10 years agoHelpfull: Yes(2) No(4)
- b=(a++)+(a++)=11+11=22
a=(b++)+(b++)=23+23=46
sooooo b=22 and a=46 - 10 years agoHelpfull: Yes(2) No(2)
- b=10+11=21
a=21+22=43
Ans:-
a=43,b=21
- 10 years agoHelpfull: Yes(2) No(1)
- A=49
B=23
- 10 years agoHelpfull: Yes(2) No(0)
- value of a & b are
a=40, b=22
- 9 years agoHelpfull: Yes(2) No(1)
- b=23 n a=43
- 9 years agoHelpfull: Yes(2) No(0)
- b=(a++)+(a++)
b=11+12=23
a=(b++)+(b++)
a=24+25=49
- 10 years agoHelpfull: Yes(1) No(5)
- so guys my bad
a++ and ++a
both increment the value of a by one
but in a++
it will return the value before increment
and ++a it will increment the value after increment
therefore answer is 21 and 43 - 10 years agoHelpfull: Yes(1) No(0)
- b=10+10=20 coz post increment operator(a++) has been used and thus it will increment only after evaluation of the expression thus a=10+1+1=12. Now by overriding a=20+20=40 with the same logic.Now b will become 22.
final result
a=40
b=22 - 10 years agoHelpfull: Yes(1) No(1)
- Guys,try this on ur complr
- 10 years agoHelpfull: Yes(1) No(1)
- b=10+11=21
a=21+22+43 - 10 years agoHelpfull: Yes(1) No(0)
- a=43 and b=23
- 10 years agoHelpfull: Yes(1) No(0)
- first a + a assigned to b
so b=20 for now
and b+ b assigned to a so 20 + 20=40
so a== 40 ans.
and now revised b= b++=11
so b= 11 + 11= 22 ans. - 10 years agoHelpfull: Yes(1) No(0)
- a=43 and b=21
- 10 years agoHelpfull: Yes(1) No(0)
- b=10+10=20
than
a=b+b=20+20=40
than b=11+11=22
thus
a=40
b=22 - 9 years agoHelpfull: Yes(1) No(1)
- b=(a++)+(a++)
b=11+11=22
a=(b++)+(b++)-?
compiler is giving a = 40 ,how? - 10 years agoHelpfull: Yes(0) No(2)
- Guys,try this on ur compliler.
- 10 years agoHelpfull: Yes(0) No(2)
- a=43 b=21 because (a++)+(a++) means 10+11 i.e 21 and same as next step
- 10 years agoHelpfull: Yes(0) No(1)
- Ans. a=40,b=22
b=10+10=20;
a=20+20=40;
after that b increases so
b=22;
- 10 years agoHelpfull: Yes(0) No(0)
- b=(a++)+(a++); a will be incremented after execution so b=10+10, b=20.and next statement also same as first statement i.e a=20+20,so a=40, and b will be incremented two times i.e b=22
final ans is a=40,b=22 - 10 years agoHelpfull: Yes(0) No(1)
- b=22,a=40;
given a=10 tnen
b=(11+11)=22;
a=23+23=46; - 10 years agoHelpfull: Yes(0) No(1)
- a=40 b=22
here
b=(a++) + (a++)
both are post increment
than b=10+10=20
but memory location 22
after a=40
ans a=40,and b=22 - 9 years agoHelpfull: Yes(0) No(1)
- a=21,b=43
.
. - 9 years agoHelpfull: Yes(0) No(2)
- b= 23 ; as b++ also used in statement a=(b++)+(b++);
b is incremented to 23
a=21+22=43 - 9 years agoHelpfull: Yes(0) No(0)
- a=40
b=22
initailly a was 10 asigned to b with post inc so value increments after adding
so,value of b=20 when incremented in a assignment it becomes 22 - 9 years agoHelpfull: Yes(0) No(0)
- a=40
b=21
a++ is postincrement so b=20
a=40
then b incremented to 21 - 9 years agoHelpfull: Yes(0) No(0)
- 10+11=21
21+22=43
a=43 b=21 - 9 years agoHelpfull: Yes(0) No(0)
- option a
int a=10,b;
b=10+11=21
a=21+22=43
- 9 years agoHelpfull: Yes(0) No(0)
- a=43 and b=23
- 9 years agoHelpfull: Yes(0) No(0)
- a=43 ,b=21 bcz a++ this is post increment so first assign the value then after increase the value
here b=(a++)+(a++) a=10 then first 10 assign after that increment the value gives 11 this is is update value again a++ take the update value and assign the value 11 so b=10+11 =21
so same rule use for a=43.
- 9 years agoHelpfull: Yes(0) No(0)
- b=(a++)+(a++) means that 10+10 = 20 will assign in B
then A will be increase two times ....after incrementing A become 12 but again a will be override by (b++) + (b++) means 20+20 =40 will assign in A.
now B will be increment two times and B become 22.
so final ans A:40 and B:22 - 9 years agoHelpfull: Yes(0) No(0)
- b=10+11=21
a=21+22=43 - 9 years agoHelpfull: Yes(0) No(1)
- its solution is 1.......
- 9 years agoHelpfull: Yes(0) No(0)
- a=43
b=21
b= 10+11
a=21+22 - 9 years agoHelpfull: Yes(0) No(1)
- ans is 3
as (a++)+(a++)= (10)+(11) which is 21 so b is now 21 but a at this time is 12......now the next line (b++)+(b++) = (21)+(22) = 43 so a=43 but b is now 23 at this time.. - 9 years agoHelpfull: Yes(0) No(0)
- a=43 b=21
because b=(a++)+(a++) means a++ is post increment so value of a will remain as 10 for first time then it will increment by 1 so b=10+11=21
same as b=21+22=43
- 9 years agoHelpfull: Yes(0) No(0)
- answer 4
so a=40,b=20 - 9 years agoHelpfull: Yes(0) No(0)
- a=43, b=23
because b=(a++) +(a++) which means a++ is post increment so the value of a is 10 in first, then it will incremented with 1 and becomes 11. therefore 10+11=21 and stores in b.
now b=21, so a=(b++)+(b++), which is also post increment, the value of b is 21 in first and 22 in second and then it will incremented to 23. so the sum would be 21+22=43 which will be stored in a.
the final values of a and b will be 43 and 23 respectively. - 5 years agoHelpfull: Yes(0) No(1)
C Other Question