トップページ > キーワード検索 > switch
C言語規格
C言語(その他)
プログラム
その他
switch
機能 多方向分岐を表す。
多方向分岐とは、制御式の結果によって各々の処理に別れる事を表す。
制御式の結果はint型で扱える整数のみ。
定義 switch ( 制御式 )
{
[ case ラベル : [文]option ]repeat
[ default : [文]option ]option
}
実装例
#include <stdio.h>

int main(void)
{
    int a = 1;
    
    switch (a)
    {
    case 0:
        printf("Case 0\n");
        break;
    case 1:
        printf("Case 1\n");
        break;
    case 2:
    case 3:
        printf("Case 2 or 3\n");
        break;
    default:
        printf("Default\n");
        break;
    }
    
    return 0;
}
実行結果
Case 1





inserted by FC2 system