第一题
第二题
第三题
#include <stdio.h>
int countChars(char* str) {
if (*str == '\0') { // 判断字符串是否为空
return 0;
} else {
return 1 + countChars(str + 1); // 递归调用函数
}
}
int main() {
char str[] = "hello world";
int count = countChars(str);
printf("The number of characters in the string is %d\n", count);
return 0;
}
运行效果