2. 补全程序题#
点击查看考点
C 风格字符串, 指针
请补全以下递归函数, 它将一个字符串前 9 个非空格字符逆序输出, 不足 9 个则遇到空白符停止.
1#include <iostream>
2
3void function(/*(1)*/) {
4 if (count == 0 || *string == '\0') {
5 return;
6 }
7
8 function(string + 1, /*(2)*/);
9 std::cout << /*(3)*/;
10}
11
12auto main() -> int {
13 function("hello", /*(4)*/); // 输出 "olleh"
14 function("helloworld", 9); // 输出 "lrowolleh"
15 function("colourful", /*(5)*/); // 输出 "lufruoloc"
16}