Control Instructions

Q1: What will be the output of the program?
#include<stdio.h>
int main()
{
    int i=4;
    switch(i)
    {
        default:
           printf('This is default\n');
        case 1:
           printf('This is case 1\n');
           break;
        case 2:
           printf('This is case 2\n');
           break;
        case 3:
           printf('This is case 3\n');
    }
    return 0;
}

A This is default
This is case 1

B This is case 3
This is default

C This is case 1
This is case 3

D This is default

ANS:A - This is default
This is case 1

In the very begining of switch-case statement default statement is encountered. So, it prints 'This is default'. In default statement there is no break; statement is included. So it prints the case 1 statements. 'This is case 1'. Then the break; statement is encountered. Hence the program exits from the switch-case block.



img not found
img

For help Students Orientation
Mcqs Questions

One stop destination for examination, preparation, recruitment, and more. Specially designed online test to solve all your preparation worries. Go wherever you want to and practice whenever you want, using the online test platform.