#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
int my_strlen(char *p)
{
assert(p != NULL);
if(! *p)
return 0;
else
return 1+my_strlen(++p);
}
int main(void)
{
char arr[] = "abcdefg";
int ptr = 0;
ptr = my_strlen(arr);
printf("%d\n", ptr);
return 0;
}
遇到的一个面试题:编写一个strlen函数,不能使用全局变量或者局部变量
最新推荐文章于 2023-09-02 17:40:38 发布