ICSE Class 10 Computer Applications
Question 24 of 30
Solved Sample Paper 1 — Question 24
Back to all questions 24
Question Question 2(iv)
Write the value of n and m after execution of the following code.
int m;
int n;
m = 5;
n = (5 * ++m) % 3;
System.out.println("n = " + n + "m =" + m);Output
n = 0m = 6
Explanation
The statement n = (5 * ++m) % 3; is evaluated as follows:
n = (5 * ++m) % 3; [m = 5]
⇒ n = (5 * 6) % 3; [Prefix operator first increments the value and then uses it. So, m = 5 + 1 = 6 and then it is used in the expression]
⇒ n = 30 % 3;
⇒ n = 0;
So, final value of m is 6 and n is 0.