Point out error, if any, in the following program main() {      int i=1;      switch(i)      {           case 1:                     printf("nRadioactive cats have 18 half-lives");                     break;           case 1*2+4:                     printf("nBottle for rent -inquire within");                     break;      } }

A)

No error


B) Runtime error
C)

None of the above

 


Explanation: Constant expression like 1*2+4 are acceptable in cases of a switch.

Showing Answers 1 - 8 of 8 Answers

supriya ahire

  • Mar 21st, 2006
 

hi,

   ans is A) no error.

     case in switch can take only constant expressions and not variable expressions

regards,

Supriya Ahire.

  Was this answer useful?  Yes

Yes,  the ans is A) i.e. No Error.
In switch case we can place any constant (only integer or character not any floating point number). Here 1*2+4 is an expression and the value of the expression is 6 i.e constant  which is applicable in switch case.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions