Archive for September, 2006

C语言:不用任何变量实现strlen

在CSDN看到一个贴:

http://community.csdn.net/Expert/TopicView3.asp?id=4976379

其中有个题目是:
strlen()的C语言实现,不能使用任何变量。 

解题方法是用递规, zenny_chen(ACE Intercessor)给出了答案。

size_t strlen(const char *s)
{
    if(!s)
        return -1;
    return (*s)? 1 + strlen(++s) : 0;
}

Leave a Comment