Aspire's Library

A Place for Latest Exam wise Questions, Videos, Previous Year Papers,
Study Stuff for MCA Examinations - NIMCET

Previous Year Question (PYQs)



What is the output for the program given below?
#include <stdio.h>
int main()
{
    char i = 2;
    switch(i)
    {
        case '1':
            printf("Black\n");
        case '2':
            printf("White\n");
        default:
            printf("Red\n");
    }
    printf("Blue");
    return 0;
}





Solution

Solution:

i = 2 (numeric), but case '2' is character constant with ASCII value 50

No case matches, so default executes → prints Red

After switch, printf("Blue") always runs


Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More


Online Test Series,
Information About Examination,
Syllabus, Notification
and More.

Click Here to
View More

Ask Your Question or Put Your Review.

loading...