ICSE Class 10 Computer Applications Question 21 of 30

Solved Sample Paper 2 — Question 21

Back to all questions
21
Question

Question 2(i)

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++;
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