#include<stdio.h>标签:arr,return,int,len,char,num,三种,字符串,长度 From: https://blog.51cto.com/u_13606048/6091837
#include<string.h>
int len_c1(char* arr) { //自定义函数(无递归)
int num = 0;
while (*arr != '\0') {
num++;
arr++;
}
return num;
}
int len_c2(char* arr) { //自定义函数(递归)
while (*arr != '\0') {
return 1 + len_c2(arr + 1);
}
return 0;
}
int main() {
char arr[] = "woshizhendeaini";
printf("字符串长度为%d\n", len_c1(arr));
printf("字符串长度为%d\n", len_c2(arr));
printf("字符串长度为%d\n", (unsigned int)strlen(arr));
return 0;
}