定义一个函数求字符串的长度,要求该函数体内不能声明任何变量

来源:互联网 发布:帮人淘宝推广怎么做 编辑:程序博客网 时间:2024/05/18 06:32
  1. #include <cstdlib>  
  2. #include <iostream>  
  3. using namespace std;  
  4. int getLen(char *str)  
  5. {     
  6.     if(*str== '/0')  
  7.         return 0;  
  8.          
  9.     return getLen(str + 1) + 1;  
  10. }  
  11. int main(int argc, char *argv[])  
  12. {  
  13.     char str[] = {"abcdefghigkl"};  
  14.       
  15.     cout << getLen(str) << endl;  
  16.       
  17.     system("PAUSE");  
  18.     return EXIT_SUCCESS;  
  19. }  
原创粉丝点击