Consider the program segment:

ICSE Class 10 Computer Applications PYQ · 2025 Paper · Section A

1(xvii)1 Mark · 2025 · Section A · 2025 Paper

Consider the program segment:

int p = 0;
for(p = 4; p > 0; p -= 2);
System.out.print(p);
System.out.println(p);

The above statement will display:

Show SolutionHide Solution↓

00

Reason

1. Initialization: int p = 0;

  • This line declares an integer variable p and initializes it to 0.

2. For Loop: for(p = 4; p > 0; p -= 2);

  • p = 4 → loop starts with p assigned the value 4.
  • Condition: p > 0 is true (since 4 > 0).
  • The semicolon (;) at the end means the loop body is empty and does nothing.
  • Update: p -= 2 decreases p by 2.
  • Next value of p = 2 → still > 0, so the loop continues.
  • Decrease again: p -= 2 → p = 0 → now the condition p > 0 is false, loop stops.

3. After the Loop: p is now 0.

4. Output Statements:

  • System.out.print(p); prints 0 without moving to the next line.
  • System.out.println(p); prints 0 and moves to the next line.
← Previous questionNext question →

Browse the free Computer Applications sample bank