Computer Applications
If a = 5, b = 9, calculate the value of a in the following expression:
a += a++ - ++b + a
Java
Java Operators
220 Likes
Answer
6
Working
a += a++ - ++b + a
⇒ a = a + (a++ - ++b + a)
⇒ a = 5 + (5 - 10 + 6) [∵ a++ will first use current value of a then increment it to 6. ++b will increment b to 10 and use the incremented value. As a++ incremented a to 6 so the value of last a in the expression is 6]
⇒ a = 5 + 1
⇒ a = 6
Answered By
111 Likes
Related Questions
What will be the output of the following if x = 5 initially?
(a) 5* ++x;
(b) 5* x++;
What will be the output of the variable 'a'?
int a=0,b=10,c=40; a = --b + c++ + b; System.out.println(" a = " + a);
If m = 5 and n = 2, predict the output values of m and n:
(a) m -= n;
(b) n = m + m/n;
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;