edited by
635 views
1 votes
1 votes

Which of the following is a valid C code to print character ‘A’ to ‘C’ ?

  1. x='A' ;
    switch(x)
    {case 'A'= printf ( "%d\n" , x);
    ....
    case  'C'= printf ( "%d\n" , x);
    }
  2. x='A';
    switch(x)
    {case  'A' <= x <= 'C'  : printf ( "%d\n" , x);}
  3. x='A' ;
    switch(x)
    {
    case  'A'  : printf ( "%d\n" , x);
    break;
    case  'B'  : printf ( "%d\n" , x);
    break;
    case  'C'  : printf ( "%d\n" , x);
    break; 
    }
  4. x='A' ; 
    switch(x)
    {
    case  'A' =printf ( "%d\n" , x);
    case  'B' =printf ( "%d\n" , x); 
    case  'C' =printf ( "%d\n" , x);
    }
edited by

1 Answer

0 votes
0 votes
Syntax of switch...case:
switch (expression)
​{
    case constant1: // statements
      break;

    case constant2:// statements
      break;
    .
    .
    .
    default:// default statements
}

Here OPTION C is according to syntax but it will print only A  character because  of break; statement

Option A,B,D is invalid according syntax

so all four option are invalid

 ANS is none of these

Related questions

1 votes
1 votes
1 answer
1
go_editor asked Mar 28, 2020
606 views
What cannot replace ‘?’ in the following C-code to print all odd numbers less than $100$ ?for (i=1; ? ; i=i+2) printf("%d\n", i);$i\leq100$$i\leq101$$i<100$$i<101$
2 votes
2 votes
1 answer
2
1 votes
1 votes
2 answers
3
go_editor asked Mar 28, 2020
1,229 views
The number of edges in a complete graph with $‘n’$ vertices is equal to :$n(n-1)$$\large\frac{n(n-1)}{2}$$n^2$$2n-1$
0 votes
0 votes
1 answer
4
go_editor asked Mar 28, 2020
524 views
A context free grammar is :type $0$type $1$type $2$type $3$