Computer Applications
int a=7, p=0, q=0;
p= ++a + --a;
q-=p;
The output of q will be:
- 13
- 14
- 15
- -15
Java Operators
20 Likes
Answer
-15
Reason — Evaluating the given expressions:
Expression | Explanation |
---|---|
p = ++a + --a | This is the first expression. Initial value of a is 7 and p is 0. |
p = 8 + --a | At this step, ++a first increments a by 1 so it becomes 8, then this incremented value is used in the expression. |
p = 8 + 7 = 15 | At this step, current value of a (which is 8) is decremented by 1 and this decremented value of 7 is used in the expression. |
q-=p ⇒ q = q - p ⇒ q = 0 - 15 ⇒ q = -15 | Shorthand operator -= subtracts p from q and assigns the result back to q. |
Answered By
6 Likes
Related Questions
double c;
int x,y,z;
x=5; y=10; z=11;
c=x*y+z/2;
The value stored in c is:- 55.0
- 55.5
- 55
- none
int m,p; m=5; p=0; p= m-- + --m; The output will be:
- 11
- 10
- 8
- 12
What will be the output of 'a' and 'b' in the expression b = a++, if int a, b; a=10?
- 10,10
- 10,11
- 11,10
- 11,11
State whether the following statement is True or False :
Java is known as an Object-Oriented Programming (OOP) language.