根據下列的 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
答案與詳解
字串 "world peace" 逐字掃描:w-o-r-l-d-空格-p-e-a-c-e,只有 'world' 尾端 1 個 'd',x 累加 1 次。
