Wednesday, September 2, 2009

Switch Case using tips in c programming

  1. if the case match with an expression execution start from the case.

Example : void main()
  int x=2;
  case 1:
 case 2:

  1. if none of the case are satisfied then the default case is satisfied

example : void main()
                        int x=102;
                                    case 10: printf(“ I am a reader”);
                                    case 11:printf(“I am writer”);
                                    default: printf(“I am programmer”);
} character must be integral constant.
4.break is used to prevent the falling of control from one case to another case

5. case can in any order.
 6.In the switch statement , the keyword ‘continue ‘ cannot be used in place of ‘break’. The compiler will generate an error message . the use of continue will not take the control to the beginning of switch as one is likely to believe.

7.duplicate case is not allowed.

8. the default case is optional . if there is no match case and there is no default case , then the compiler does not report the error. character can be constant or constant expression but not variable.

10. if 0 is given as an argument in if , while and do-while , it  evaluates to false but in switch it evaluates as an expression.

11. switch case used for menu driven program

No comments:

Blog List