2.#
点击查看考点
C 风格字符串, 递归函数
1#include <iostream>
2
3using namespace std;
4
5void print(char const* s, int& num) {
6 if (*s == '\0') {
7 return;
8 }
9 num++;
10 print(s + 1, num);
11 cout << *s;
12}
13
14int main() {
15 int n = 0;
16 char str[] = "chatgpt";
17 print(str, n);
18 cout << endl << n;
19}