search
Log In
0 votes
71 views
#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?
in Programming 71 views

1 Answer

3 votes
 
Best answer

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
1 answer
1
101 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; }
asked Apr 12, 2019 in Programming altamash 101 views
2 votes
1 answer
2
399 views
int main() { int m=44; int*p=&m; int &r=m; int n=(*p)++; int *q=p-1; r=--*(p)+1; ++*q; printf("m=%d n=%d r=%d",m,n,r); return 0; } Options: m=44,n=46,r=45 m=45,n=44,r=45 m=46,n=44,r=46 m=46,n=43,r=46
asked Mar 10, 2019 in Programming Nishi Agarwal 399 views
0 votes
1 answer
3
124 views
void f(int x,int &y,const int &z) {x+=z; y+=z; } int main() { int a=22,b=33,c=44; f(a,b,c); f(2*a-3,b,c); printf("a=%d b=%d c=%d",a,b,c); return 0; }
asked Mar 10, 2019 in Programming Nishi Agarwal 124 views
0 votes
0 answers
4
128 views
What is the output of the following code ? void f(int a, int b){ printf(“%d”,a+b); } void main() { f((2,3),4); } 6 7 5 None of these
asked Jan 10, 2019 in Programming register_user_19 128 views
...