1.
What will be the output for the
following program segment?
int a=0,b=30,c=40;
a= --b + c++ +b;
System.out.println("a="+a);
Ans: 29 + 40 + 29
= 98
2.Evaluate the following expressions, if
the values of the variables are a=2, b=3
and c=9:
(a) a-(b++)*(--c)
(b) a*(++b)%c
Ans: (a) -22
(b) 8
3. If a=5, b=9, calculate the value of
a+=a++ - ++b +a.
Ans: 5 + 5 - 10 + 6
= 10 - 10 + 6
=6
4. What will be the output of the
following code?
int k=5, j=9;
k+=k++ - ++j + k;
System.out.println("j="+j);
System.out.println("k="+k);
Ans: j=10
k=6
5. What is the result produced by 2-
10*3+100/11?
Ans: 2-10*3+100/11
= 2 - 30 + 9
= -28 + 9
= -19
6. int x=20, y=10, z;
What is the value of z in
z = ++x * (y--) - y?
Ans: z = ++x * (y--) - y
= 21 * 10 - 9
= 210 - 9
= 201
7. What will be the output of the
following code segment?
int a=15, b=21, c;
What is the value of c in
c= ++a + b++ * a++ - b;
Ans: 16 + 21 * 16 - 22
= 16 + 336 - 22
= 352 - 22
= 330
8. Evaluate the value of the following
expression if x=9 and y=19 initially:
(++x) + y + (x++) + (++y) + x + (y++) + 29.
Ans: 10 + 19 + 10 + 20 + 11 + 20 + 29
= 119
9. If x=9, y=5, determine the value of x
after executing:
x+=(++x) % y;
Ans: 9 + 10 % 5
=9+0
=9
10. If a=6, b=2 and c=3.5, then evaluate x
and y as follows:
(i) x = a - (b++) * (-c);
(ii) y = (++b) * a - b;
Ans: x = 13.0
y = 15
11. If x = 20, determine the value of:
x += x * x - ((--x) * (x--))
Ans: 20 + 20 * 20 - (19 * 19)
= 20 + 400 - 361
= 420 - 361
= 59
12. If x = 4, the determine the value of
(x++) + (++x)
Ans: 4 + 6
= 10
13.Given: x += x++ + ++x + --x
Find the value, when x=5.
Answer
x = 5 + (5 + 7 + 6)
x = 5 + 18
x = 23
14.What will be the output of the
following code?
int k=5,j=9;
k += k++ - ++j + k;
System.out.println("k="+k);
System.out.println("j="+j);
Answer
k+= k++ - ++j + k
⇒ k = k + (k++ - ++j + k)
⇒ k = 5 + (5 - 10 + 6)
⇒k=5+1
⇒k=6
k=6
j=10
15.If int y =10 then find int z = (++y*(y++
+ 5));
Answer
z = (++y * (y++ + 5))
⇒ z = (11 * (11 + 5))
⇒ z = (11 * 16)
⇒ z = 176
16.Give the output of the following
expression:
a += a++ + ++a + --a + a--; when a = 7;
Answer
a+= a++ + ++a + --a + a--
⇒ a = a + (a++ + ++a + --a + a--)
⇒ a = 7 + (7 + 9 + 8 + 8)
⇒ a = 7 + 32
⇒ a = 39
17.What is the value of y after the
execution?
y += ++y + y-- + --y; when int y=8
Answer
y+= ++y + y-- + --y
⇒ y = y + (++y + y-- + --y)
⇒ y = 8 + (9 + 9 + 7)
⇒ y = 8 + 25
⇒ y = 33
18.int a=3, b=7;
a*=++a + --b + a--;
System.out.println (a+","+b);
Answer
a*=++a + --b + a--
a=a*(++a + --b + a--)
a=3*(4+6+4)
3*14
42
Answer 42 , 6
19.int x= -2, y= -3;
x+=--x - ++y + ++x;
System.out.println ("x="+x);
System.out.println ("y="+y);
Answer
x+=--x - ++y + ++x;
x=x+(--x - ++y + ++x);
=-2+(-3 -(-2)+-2)
=-2+(-3+2-2)
=-2-3
=-5
x=-5
y=-2
20.If a = 8; then find the value of
a- = ++a + a++ + 4;
Answer
a-= ++a + a++ +4;
a=a-(++a + a++ +4);
=8-(9+9+4)
=8-22
=-14
21. If x = 4;
find the value of
x+= x++ * ++x % 2;
x+= x++ * ++x % 2;
x=x+(x++ * ++x % 2);
=4+(4 * 5 %2)
=4+(20%2)
=4