Skip to content
Official PYQ · 1995

GATE CS 1995 Q1.4 — Asymptotic Worst Case Time and Space Complexity

Explain with AI

In the following Pascal program segment, what is the value of X after the execution of the program segment?

X := -10; Y := 20;
If X > Y then if X < 0 then X := abs(X) else X := 2*X;
Choose one option
View worked solution

Answer: C

Let's trace the execution of the given Pascal program segment step-by-step:

  1. Initialization:

    X=−10,Y=20X = -10, \quad Y = 20

  2. Conditional Evaluation:

    The statement is:

    If X > Y then if X < 0 then X := abs(X) else X := 2*X;

    We first evaluate the outer condition: X > Y.

    Substituting the values:

    −10>20  ⟹  False-10 > 20 \implies \text{False}

  3. Execution Flow:

    Since the outer if condition is False, the control bypasses the entire nested statement (regardless of how the else is paired due to the dangling-else rule).

    Consequently, no assignment to XX takes place.

Thus, the value of XX remains unchanged at its initial value, which is −10-10.

Therefore, the correct option is C.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Asymptotic Worst Case Time and Space Complexity questions