Machine-translated by Google. Questions are authored in English.
Top

Discussion

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;
} 

 

  • A.Geeks
  • B.Quiz
  • C.GeeksQuiz
  • D.Compile-time error

Answer: C

Correct answer: GeeksQuiz

'0' is a character constant, and its value is the ASCII code 48, not the number 0. Likewise '1' is 49. The controlling expression is 0, which matches neither, so control falls to default.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.