本文共 349 字,大约阅读时间需要 1 分钟。
定义一个函数求字符串的长度,要求该函数体内不能声明任何变量
#include <cstdlib>#include <iostream>using namespace std;int getLen(char *str){ if(*str== '/0') return 0; return getLen(str + 1) + 1;}int main(int argc, char *argv[]){ char str[] = {"abcdefghigkl"}; cout << getLen(str) << endl; system("PAUSE"); return EXIT_SUCCESS;}
使用递归实现...
转载地址:http://ejkqb.baihongyu.com/