Control Instructions

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

A Hello
Hi

B Hello
Bye

C Hi

D Bye

ANS:A - Hello
Hi

switch(i) has the variable i it has the value '1'(one). Then case 1: statements got executed. so, it prints 'Hi'. The break; statement make the program to be exited from switch-case statement. switch-case do not execute any statements outside these blocks case and default Hence the output is 'Hi'.



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.