c语言case的使用注意问题

#include <stdio.h>
  2 int main()
  3 {
  4         int i;
  5         printf ("input somenum");
  6         scanf ("%d" , &i);
  7         switch (i)
  8         {
  9                 //case (0.1+0.9)://这样是不行的case后面必须是一个整数
 10                 //      printf ("this is 1\n");
 11                 //      break;
 12                 case -1://这样是可以的,,,可以看出case后面应是一个有符号的整数
 13                         printf ("this is -1\n");
 14                         break;
 15                 case 'a'://这是可行的,,,后面跟字符是可以的
 16                         printf ("this is a\n");
 17                         break;
 18                 case 2:
 19                         printf ("this is 2\n");
 20                         break;
 21                 case 3:
 22                         printf ("this is 3\n");
 23                         break;
 24                 case 4:
 25                         printf ("this is 4\n");
 26                         break;
 27                 default :
 28                         printf ("this is not 1234\n");
 29                         break;
 30         }
 31         //getchar();
 32         //getchar();
 33         setbuf(stdin,NULL);
 34         char j;
 35         scanf ("%c", &j);
 36         switch (j)
 37         {
 38                 case 'a':
 39                         printf ("this is a\n");
 40                         break;
 41                 default:
 42                         printf ("this is default\n");
 43                         break;
 44         }
 45 /*      getchar();
 46         getchar();
 47         char k;
 48         scanf ("%c", &k);
 49         switch (k)
 50         {
 51                 case "a":这里是错误的也就是说case后面只能跟整形和与整形通用的字符型并且只能是字符而不能是字符串
 52                         printf ("this is a\n");
 53                         break;
 54                 default:
 55                         printf ("this is default\
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值