c語言中case是什麼
Ⅰ c語言裡面的case 是什麼意思
case是和switch配套使用的,case後面加的數字是用來判斷switch後臘態褲加的數字的,即如果switch後面加的是1,那麼就執行case 1這條語句,當然如果case 1這條語句里沒有加break,那麼輪簡就會順序執行下去,即繼續執行case 2,直到出閉純現break。
Ⅱ c語言中case是什麼意思
case 是開關語句的一個組成部分。
用法:
case 下面必須是整型常數。
冒號和break;之間是滿足這個case時要執行的語句。
例如:
switch (整型表達式)
{
case 1: printf("case 1 "); break;
case 2: case 5: printf("case 2 or 5
"); break;
...
default: ...break;
}
當整型表達式得1,列印字元串 "case 1"
當整型表達式得2或5,列印字元串 "case 2 or 5"
(2)c語言中case是什麼擴展閱讀:
c語言case的使用注意問題
#include <stdio.h>
int main()
{
int i;
printf ("input somenum");
scanf ("%d" , &i);
switch (i)
{
//case (0.1+0.9)://這樣是不行的case後面必須是一個整數
// printf ("this is 1 ");
// break;
case -1://這樣是可以的,,,可以看出case後面應是一個有符號的整數
printf ("this is -1 ");
break;
case 'a'://這是可行的,,,後面跟字元是可以的
printf ("this is a ");
break;
case 2:
printf ("this is 2 ");
break;
case 3:
printf ("this is 3 ");
break;
case 4:
printf ("this is 4 ");
break;
default :
printf ("this is not 1234 ");
break;
}
//getchar();
//getchar();
setbuf(stdin,NULL);
char j;
scanf ("%c", &j);
switch (j)
{
case 'a':
printf ("this is a ");
break;
default:
printf ("this is default ");
break;
}
/* getchar();
getchar();
char k;
scanf ("%c", &k);
switch (k)
{
case "a":這里是錯誤的也就是說case後面只能跟整形和與整形通用的字元型並且只能是字元而不能是字元串
printf ("this is a ");
break;
default:
printf ("this is default