2009年腾讯校园招聘笔试题! 不使用任何中间变量求一个const字符串长度

 具体题目是不使用中间变量实现strlen函数,(strlen为c语言里面求字符串长度库函数)。

给出了一个函数声明:

int strlen(const char *p);

 

虽然我没有参加,但是听人家这么说起这个题目,呵呵方便大家看看!

这里给出我的实现,希望高手指点!

  1. int strlen_my(const char *p);
  2. int main(){ 
  3.     const char *p  = "ok!";
  4.     int a = strlen_my(p);
  5. int strlen_my(const char *p) {
  6.     if (p==NULL)
  7.     {
  8.         return 0;
  9.     }
  10.     if (*p == '/0')
  11.     {
  12.         return 0;
  13.     }
  14.     else 
  15.         return 1+strlen_my(++p);
  16. }

呵呵,腾讯居然不给我笔试机会,哎,水平太垃圾了,投哪个公司人家受笔试,我受鄙视!

你可能感兴趣的:(c,腾讯,null,招聘,语言)