What will be output when you will execute following code?

What will be output when you will execute following c code?

#include<stdio.h>

#define TRUE 1

void main(){

switch(1){

printf("abcdefghijklmnopqrstuvwxyz");

}

}

  1. A.

    abcdefghijklmnopqrstuvwxyz

  2. B.

    It will print nothing

  3. C.

    Runtime error

  4. D.

    Compilation error

Attempted by 293 students.

Show answer & explanation

Correct answer: B

Step 1: Behavior of switch

  • In C, the body of a switch statement must contain case or default labels.

  • Any statement not under a case or default is unreachable and will not be executed.

Step 2: What happens here

  • switch(1) is valid and correctly structured.

  • The printf statement is present but not under any case or default label.

  • Therefore, the printf statement is unreachable and will not execute.

Step 3: Output

  • Since no statement in the switch body is executed, the program produces no output.

Explore the full course: Dsssb Tgt Computer Science Paper 2