C/C++

2009年腾讯校园招聘笔试题

[ 不指定 2008/11/01 14:31 | by wxxslt ]
不使用中间变量实现strlen函数,(strlen为c语言里面求字符串长度库函数)。给出了一个函数声明:
int strlen(const char *p);

#include<iostream.h>
int strlen_my(const char *p);
void main()
{  
    const char *p="wenxueba.net";
    int length=strlen_my(p);
cout<<length<<endl;
}  
int strlen_my(const char *p)
{
if(p==NULL)
    {
        return 0;
    }
    if(*p=='\0')
    {
        return 0;
    }
    else  
        return 1+strlen_my(++p);
}
Pages: 1/1 First page 1 Final page [ View by Articles | List ]