What is the output of the following program? void main() { printf("1"); goto…

2026

What is the output of the following program?

void main()

{

printf("1");

goto xyz;

printf("2");

xyz:

printf("3");

}

Answer: D. 13In C, the statement goto label; performs an unconditional jump to a point marked label: within the same function. A label must be followed by a colon, not a…

  1. A.

    1 2

  2. B.

    23

  3. C.

    1 2 3

  4. D.

    13

Attempted by 216 students.

Show answer & explanation

Correct answer: D

In C, the statement goto label; performs an unconditional jump to a point marked label: within the same function. A label must be followed by a colon, not a semicolon — label: marks a jump target, while label; would instead be read as an ordinary (and here, undeclared) expression statement. The instant execution reaches a goto, control moves straight to its target label; every statement written between the goto and the label is skipped, and normal top-to-bottom execution resumes from the label onward.

  1. Control enters main and executes the first statement, printf("1"), so 1 is printed.

  2. The next statement is goto xyz;, an unconditional jump to the label xyz:. Control transfers there immediately, so the intervening printf("2") never runs.

  3. Execution resumes at xyz: and continues to the next statement, printf("3"), so 3 is printed.

  4. No further statements remain, so the characters actually printed, in the order they were printed, form the complete output.

  • If the goto line were removed, execution would fall straight through every statement in source order, printing all three characters — confirming that it is specifically the jump, not some other effect, that removes the middle print from the output.

  • The label xyz: itself performs no printing; it only marks where execution resumes after the jump, so it contributes nothing extra to the output.

The two prints that actually execute, in order, produce the output 13.

Explore the full course: Accenture Preparation

Loading lesson…