Examly題庫立即開始練習
2 類科共用卷
普考-電信工程普考-電子工程
計算機概要11330單選題

根據下列的 C++語言函數宣告,呼叫 calculate("world peace"),函數的回傳值為何? #include <iostream> using namespace std; int calculate(string s) { int x =0; for (int i=0; i<s.length(); i++) if (s[i] == 'd') x++; return x; }

A0
B1正確答案
C4
D11
答案與詳解
B
正確答案
函數計算字串中字母 'd' 出現次數,"world peace" 只有 1 個 d,回傳 1。

為什麼答案是 B

字串 "world peace" 逐字掃描:w-o-r-l-d-空格-p-e-a-c-e,只有 'world' 尾端 1 個 'd',x 累加 1 次。

考點:誤判無 d考點:字元計數考點:誤算其他字元考點:誤取字串長度
載入中…

計算機概要 相關題目

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

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

Download on theApp Store即將推出Google Play
黑皮