MCQ Practice Single Best Answer Topic: ICSE Computer Application - Class X - 2025 SPECIMEN QUESTION PAPER

Q

Consider the following program segment to swap two variables a and b using a third variable. The statements are jumbled. Arrange them in the correct order to perform the swap successfully:


void swap(int a, int b)
{
    a = b;      // (1)
    b = t;      // (2)
    int t = 0;  // (3)
    t = a;      // (4)
}

Question ID
#24271
Subchapter
ICSE Computer Application - Class X - 2025 SPECIMEN QUESTION PAPER
Action
Choose one option below

Choose Your Answer

Click an option to check whether your answer is correct.

  • A (a) (1) → (2) → (3) → (4)
  • B (b) (3) → (4) → (1) → (2)
  • C (c) (1) → (3) → (4) → (2)
  • D (d) (2) → (1) → (4) → (3)
Correct Answer: B

Explanation

We are asked to swap two variables a and b using a third variable t. Let's carefully analyze the correct sequence.

The standard swapping logic using a temporary variable t is:

  1. Declare tint t = 0;

  2. Store a in tt = a;

  3. Assign b to aa = b;

  4. Assign t to bb = t;

So, the correct order of statements:

int t = 0; → t = a; → a = b; → b = t;

Looking at the labels given in the question:

  • a = b; → (1)

  • b = t; → (2)

  • int t = 0; → (3)

  • t = a; → (4)

Mapping to our logic: 3 → 4 → 1 → 2

Answer: (b) (3) (4) (1) (2)

Share This Question

Share this MCQ with your friends or study group.