ICSE Class 10 Computer Applications Question 26 of 30

Solved Sample Paper 4 — Question 26

Back to all questions
26
Question

Question 2(vi)

What will be the output of the following code?

int num = 10; 
if (num < 20)
    System.out.print(num++);
else
    System.out.print(--num);
Answer
Output
10
Explanation

Since the condition (num < 20) is true, the if block is executed. Postfix operator first uses the value and then increments the value, so the value of num is first printed (10) and then incremented.

Get the Bright Tutorials app Stuck on a question? Ask Bright Buddy — your AI tutor — for step-by-step help in the app.