264 views
0 votes
0 votes
#include <stdio.h>
int main()
{
    //int a;
    char c='a';
    switch(c){
        case 'a' && 1:printf("gate");
        case 'b' && 1:printf("cse");
                      break;
        default: printf("2018");
    }

    return 0;
}

what is the output for the program?

1 Answer

Best answer
3 votes
3 votes

Output

It will return error because of using duplicate case value

Reason 

'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

  switch(c)

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

}

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

selected by

Related questions

0 votes
0 votes
1 answer
1
0 votes
0 votes
1 answer
4
altamash asked Apr 12, 2019
321 views
int main();{int a,*b, c, *d, e;a=10;b=&a;c=&b;d=&c;e=&d;print f(“a=%d b=%u c=%u d=%u e=%u e=%u\n”, a,b,c,d,e);print f(“ %d %d %d \n”,a,a+*b, c+ *d+, e);return 0...