Computer Applications
What will be the result stored in x after evaluating the following expression?
int x = 4;
x += (x++) + (++x) + x;
Java Operators
ICSE 2012
102 Likes
Answer
x += (x++) + (++x) + x
⇒ x = x + ((x++) + (++x) + x)
⇒ x = 4 + (4 + 6 + 6)
⇒ x = 4 + 16
⇒ x = 20
Answered By
62 Likes
Related Questions
A student executes the following code to increase the value of a variable ‘x’ by 2.
He has written the following statement, which is incorrect.
x = +2;What will be the correct statement?
A. x +=2;
B. x =2;
C. x = x +2;- Only A
- Only C
- All the three
- Both A and C
A store has purchased some cola cans of various brands. It purchased 50 cans @ ₹15 per can, 30 cans @ ₹20 per can and 40 cans @ ₹21 per can. Write a Java program to compute how much amount did the store pay.
Rewrite the following program segment using logical operators:
if(x > 5) if(x > y) System.out.println(x + y);Evaluate the expression when x is 4:
x += x++ * ++x % 2;