Increment and Decrement Operators
Give the output:
1. a+=++a-b-- + a+b where a=2 and b=6
a=a+ ++a-b-- + a+b
=2+3-6+3+5
=5-6+3+5
=13-6
=7
2. x=x++ + (++x)%5 where x=10
10+12%5
10+2
=12
3. m*=m+n++ + ++m where m=20 and n=15
m*=20+15 + 21
m*= 56
m=m*56
m=20*56
m=1120
4. q=(++q/p-- + q++)*p/4 where p=75 and q=90
(91/75+91)*74/4
(1+91)*74/4
=92*74/4
=6808/4
=1702
5. a+=--a + b*3 + c++ - ++b where a=2, b=3 and c=10
a+=1+3*3 + 10-4
a+=1+9+6
a+=16
a=a+16
a=2+16
a=18
6. z=(++y*(y++ + 5)) where z=10
=11*(11+6)
=11*17
7. a+=a++ + ++a + --a + a-- where a=7
a+=7+9+8+8
a+=32
a=a+32
a=7+32
a=39
8. int i=0;
while(++i<10)
{
System.out.print(" "+i);
}
Output: 1 2 3 4 5 6 7 8 9
9. int i=0;
while(i++<10)
{
System.out.print(" "+i);
}
Output: 1 2 3 4 5 6 7 8 9 10
10. int i=0,j=10;
for(;++i<j-- )
{
System.out.print(i + “:”+j);
}
Output:
1 9
2 8
3 7
4 6
11. int a=10,b=5;
for(int i=0;i<10;i++)
{
int c=a++ + --b;
System.out.print( c + “ “);
}
Output:
14 14 14 14 14 14 14 14 14 14
12. a=16, b=-1
int a=5,b=6,c=7;
a*=a++ + ++a + b-- * ++c;
=5 + 7+6*8
=5+7+48
=60
a=a*60
=5*60
=300
13. int a=10, b=11,c=12;
int d=a++ * a++ + ++b/c++ + c++;
=10*11+1+13
=110+14
=124
14. x=10
x=x++ + ++x%5
=10+12%5
=10+2
=12
15. int a=2,b=6;
a+=++a – b-- + a+b
=3-6+3+5
=5
a=a+5
a=2+5
=7
16. int n=15, m=20
m*=m+ n++ + ++m;
=20+15+21
=56
m=m*56
m=20*56
=1120
17. int p=75, q=90
q=(++q/p--+q++)*p/4
=(91/75+91)*74/4
(1+91)*74/4
92*74/4
23*74
18. y=10
z=(++y*(y++ + 5))
= 11*(11+5)
=11*16
= 176
19. a+=a++ + ++a + --a+a—
a=7
7+9+8+8
=32
a=a+32
a=7+32
=39
20. a=2,b=3,c=10
a+=--a+b*3+c++ - ++b;
=1+9+10-4
=16
a=a+16
=2+16
=18
I think no. 4's answer will be 1656. Kindly check, there is a mistake.
ReplyDeleteThanks for the rectification but it will be 1702
ReplyDeleteI think no 1 will be 7 as 13-6=7
ReplyDeleteYes. Thanks
DeleteI think question no.1 is mistake
ReplyDeleteYes. Thanks
ReplyDelete