當前位置:首頁 » 編程語言 » c語言中case是什麼

c語言中case是什麼

發布時間: 2025-03-28 15:18:12

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

熱點內容
電視下架緩存的還能看嗎 發布:2025-07-12 19:14:12 瀏覽:444
安卓平板微軟平板和蘋果哪個好 發布:2025-07-12 19:09:37 瀏覽:413
資料庫地區 發布:2025-07-12 19:05:41 瀏覽:395
如何檢查vds腳本 發布:2025-07-12 19:04:24 瀏覽:908
命令行編譯vs2013 發布:2025-07-12 19:01:22 瀏覽:808
c語言輸出所有素數 發布:2025-07-12 19:01:19 瀏覽:659
查電費賬號密碼多少 發布:2025-07-12 18:56:19 瀏覽:545
吉利遠景x1標配配置有哪些 發布:2025-07-12 18:56:18 瀏覽:533
智能演算法pdf 發布:2025-07-12 18:46:07 瀏覽:400
php生成短鏈接 發布:2025-07-12 18:44:37 瀏覽:843