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");
}
}
- A.
Sangakkara
- B.
Sehwag
- C.
Steyn
- 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.