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

Discussion

Predict the output of the below program:

#include <stdio.h>
int main()
{
    int i = 3;
    switch(i)
    {
        printf("Outside ");
        case 1: printf("Geeks");
            break;
        case 2: printf("Quiz");
            break;
        defau1t: printf("GeeksQuiz");
    }
    return 0;
}

 

  • A.Outside GeeksQuiz
  • B.GeeksQuiz
  • C.Nothing gets printed

Answer: C

Correct answer: Nothing gets printed

Two things happen here. The printf("Outside ") sits inside the switch body but before any label, so control never reaches it - a switch jumps straight to a matching label. And defau1t is spelt with the digit one, so it is an ordinary goto label, not the default case. With i equal to 3 nothing matches and there is no real default, so the switch does nothing at all.

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

Post your comment

Please log in or register to post a comment.