C | Loops & Control Structure | Question 16

What is the output of the following program?

filter_none

edit
close

play_arrow

link
brightness_4
code

#include <stdio.h>
int main()
{
    char check = 'a';
    switch (check)
    {
        case 'a' || 1: printf("Geeks ");
          
        case 'b' || 2: printf("Quiz ");
                    break;
        default: printf("GeeksQuiz");
    }
    return 0;
}

chevron_right


(A) Geeks
(B) Geeks Quiz
(C) Geeks Quiz GeeksQuiz
(D) Compile-time error


Answer: (D)

Explanation: An expression gets evaluated in a case label. Both the cases used are evaluated to 1(true). So compile-time error: duplicate case value is flashed as duplicated cases are not allowed.

Quiz of this Question

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up