switch
ç¥äººã C ã®ãããªã³ã¼ããæã¡åºãã¦ããã
switch(0){putchar('A');}
ããã¯æ®éã¯å®è¡ãã¦ãæå A ã¯åºåãããªãã®ã ãã Borland C ã§ã¯åºåãããã®ã ããã ã
ã§ãè¦æ ¼ (JISX3010) ã§ã¯ã©ããªã£ã¦ããã®ãã¨èª¿ã¹ã¦ã¿ããåºåãããªãã®ãæ£ããããã ãè¦ç´ããã¨ãå¶å¾¡å¼ã®å¤ã«å¯¾å¿ãã case
ã©ãã«ã«è·³ã³ã対å¿ãã case
ã©ãã«ãç¡ãå ´å㯠default
ã©ãã«ã«è·³ã¶ã 対å¿ãã case
ã©ãã«ã default
ã©ãã«ãç¡ããã°ä½ãããªãããã¨ãããã¨ã§ããã ä¸ã®ä¾ã§ã¯å¯¾å¿ãã case
ã©ãã«ã default
ã©ãã«ãç¡ãã®ã§ããããä½ãããªãã å®ç¾©ã¨ãã¦ã¯å®ã«ã·ã³ãã«ãªãã®ã§ãæè¦çã«ãç¹ã«é¸è±ãã¦ã¯ããªãã¨æãã
è¦æ ¼ã® switch
æã®è¨è¿°å
ã§èå³æ·±ãä¾ãè¦ä»ããã 以ä¸ããã®ä¾ãå¼ç¨ãããã®ã ã
switch(expr) { int i=4; f(i); case 0: i=17; default: printf("%d\n",i); }
ãã¦ã printf
ã¯ä½ãåºåããã ãããã çµè«ããè¨ãã° expr
ã 0 ã®å ´åã« 17 ãåºåããã®ãé¤ãã°ä¸å®ã§ããã è¦æ ¼ã®ä¸ã§ããããä¾ã¾ã§æ¸ãã¦ããã®ã ããããããããã¨ããã ã¨èãããã¦ããã®ã ããã
å¶å¾¡å¼ã«å¯¾å¿ãã case
ã©ãã«ãç¡ãå ´åã«ã¯ default
ã©ãã«ã¸è·³ã¶ã®ã ãã i=4
ã¯å®è¡ããããå³ã¡ä¸å®ã¨ããããã ã ãã¡ãã f(i)
ãå®è¡ãããªãã ã ã int i
ã¨ããå¤æ°ã®å°å
¥ã¯æå¹ãªãã§ããã å¤æ°ã®å®£è¨ã¯ OK ã§åæåã¯ç¡å¹ã¨ããã®ã¯ããã«ãä¸æ ¼å¥½ã ã¨æãã
Document ID: 1b1335a3f0124defa04e259d6ec5991a