KnowledgeBoat Logo
|

Computer Applications

Write the values of c and d after execution of following code.

int a = 1; 
int b = 2; 
int c; 
int d; 
c = ++b; 
d = a++; 
c++;

Java Operators

7 Likes

Answer

After the execution of the code, c = 4 and d = 1.

Explanation
StatementRemarks
c = ++b;Prefix operator first increments and then uses the value. Thus, c = 3, b = 3
d = a++;Postfix operator first uses and then increments the value. Thus, d = 1, a = 2
c++;c = c + 1
= 3 + 1
= 4

Answered By

3 Likes


Related Questions