C | Loops & Control Structure | Question 3
What is the output of the below program?
#include <stdio.h> int main() { int i = 0; switch (i) { case '0': printf("Geeks"); break; case '1': printf("Quiz"); break; default: printf("GeeksQuiz"); } return 0; } |
chevron_right
filter_none
(A) Geeks
(B) Quiz
(C) GeeksQuiz
(D) Compile-time error
Answer: (C)
Explanation: At first look, the output of the program seems to be Geeks. But, the cases are labeled with characters which gets converted to their ascii values 48(for 0) and 49(for 1). None of the cases is labeled with value 0. So, the control goes to the default block and GeeksQuiz is printed.
Recommended Posts:
- C | Loops & Control Structure | Question 1
- C | Loops & Control Structure | Question 9
- C | Loops & Control Structure | Question 2
- C | Loops & Control Structure | Question 4
- C | Loops & Control Structure | Question 5
- C | Loops & Control Structure | Question 16
- C | Loops & Control Structure | Question 18
- C | Loops & Control Structure | Question 17
- C | Loops & Control Structure | Question 6
- C | Loops & Control Structure | Question 7
- C | Loops & Control Structure | Question 19
- C | Loops & Control Structure | Question 20
- C | Loops & Control Structure | Question 10
- C | Loops & Control Structure | Question 21
- C | Loops & Control Structure | Question 8



