当前位置: 代码迷 >> 综合 >> switch与case及default
  详细解决方案

switch与case及default

热度:29   发布时间:2024-01-17 06:01:31.0

switch ( controllingExpression ) 
{ 
  case constantExpression1 : 
  case constantExpression2 : 
  case constantExpression3 :

       default:

}

switch后括号中可以是varible与controllingExpression:

case后只能是整形或字符型的常量或常量表达式。

int c;c=‘a’;int var=5;

switch(c)

{

           case  “a”:      错

           case  var :     错

           case  NULL :  错

           case  1.1+0.9 :错

           case  3/2 :    对

           case  3%2 : 对

           case  1+2 :  对

           case  -1 :  对

           case  ‘a’ :  对

}

  相关解决方案