Examly題庫
公務人員特種考試關務人員計算機概要111 年第 26 題單選題考點:fall-through考點:switch fall-through

執行下列 C 程式後,產生的輸出為何? #include<stdio.h> int main(){ int i; for(i= 0; i < 3; i++){ switch(i){ case 0: break; case 1: printf("one "); case 2: printf("two "); case 3: printf("three "); } printf("four "); } return 0; }

Afour one four two four
Bfour one two three four two three four正確答案
Cone two three four two three four three four
Dfour one two three four two three four three four
答案與詳解
B
正確答案
本題測驗 switch-case 的 fall-through 特性與 break 行為,需逐次追蹤迴圈輸出結果。

逐選項解析

Afour one four two fourfall-through✕ 錯誤
此選項假設每個 case 都有 break,忽略了 case 1 與 case 2 缺少 break 造成的 fall-through 效果。
Bfour one two three four two three fourswitch fall-through✓ 正確
i=0 時 case 0 有 break 跳出 switch,印 four;i=1 時 case 1 無 break,fall-through 依序印 one two three,再印 four;i=2 時 case 2 無 break,fall-through 印 two three,再印 four。合併為 four one two three four two three four。
Cone two three four two three four three four✕ 錯誤
Dfour one two three four two three four three four✕ 錯誤

立即註冊,看完整詳解

這題的完整詳解,註冊就能看 · 每天 2 題免費

精選詳解
  • 完整逐選項解析
  • 秒殺解題技巧與破題關鍵
  • 關鍵知識表整理
  • 陷阱與易錯提醒
  • 同考點歷屆題庫連續刷題與錯題本
接著練習整份考卷查看 111 年 111年公務人員特種考試關務人員考試、111年公務人員特種考試身心障礙人員考試、111年國軍上校以上軍官轉任公務人員考試《計算機概要》完整試題與解答

計算機概要 相關題目

想練更多計算機概要考古題?

Examly 收錄 50 萬+ 道歷屆題目,每題都有像這樣的精選詳解。免費下載,立即開練。

Examly