What will be output when you will execute following code?

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

#include<stdio.h>

void main(){

switch(6){

case 6.0f: printf("Sangakkara");

break;

case 6.0: printf("Sehwag");

break;

case 6.0L: printf("Steyn");

break;

default: printf("Smith");

}

}

  1. A.

    Sangakkara

  2. B.

    Sehwag

  3. C.

    Steyn

  4. D.

    Compilation error

Attempted by 499 students.

Show answer & explanation

Correct answer: D

In C, case labels in a switch must be constant expressions of an integral type (like int or char). Floating-point constants such as 6.0f, 6.0, and 6.0L are not allowed as case labels. This makes the code invalid and results in a compilation error.

Explore the full course: Dsssb Tgt Computer Science Paper 2