The Gateway to Computer Science Excellence
0 votes
#include <stdio.h>
int main()
    //int a;
    char c='a';
        case 'a' && 1:printf("gate");
        case 'b' && 1:printf("cse");
        default: printf("2018");

    return 0;

what is the output for the program?
in Programming by Active (1.2k points) | 57 views

1 Answer

+3 votes
Best answer


It will return error because of using duplicate case value


'a' && 1 will give us 1 (i.e true bcz non zero Value anded with non zero value gives 1)

Similarly case 'b' && 1 will also give us 1

So our program becomes


        case 1:   printf("gate");  
        case 1:  printf("cse");
        default: printf("2018");


Due to duplicate case value we can't able to decide which case to select

by Active (3.3k points)
selected by
Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,741 questions
57,253 answers
104,700 users