KnowledgeBoat Logo
|

Computer Applications

Write the values of r and s after the execution of the following code.

int p = 11, q = 21, r, s; 
r = ++q;
s = p++; 
r++;

Java Operators

2 Likes

Answer

After execution of the given code, r = 23 and s = 11.

Explanation
StatementRemarks
int p = 11, q = 21, r, s;p = 11, q = 21, r and s are declared
r = ++q;r = 22 (prefix operator first increments the value and then uses it)
s = p++;s = 11 (postfix operator first uses the value and then increments it)
r++;r = 23 (value of r is incremented by 1)

Answered By

1 Like


Related Questions