您的位置:首页 > 编程语言 > C语言/C++

C++ primer(第五版) 练习 6.7 个人code

2014-08-03 22:31 411 查看
C++ primer(第五版) 练习 6.7

题目:

编写一个函数,当它第一次被调用时返回0,以后每次调用返回值加1。

以下是我无脑的答案:

#include <iostream>

using std::cout;
using std::cin;
using std::endl;

int test()
{
static int jubujingtaibianliang = 0;
return jubujingtaibianliang++;
}

int main()
{

cout << test() << endl;
cout << test() << endl;
cout << test() << endl;
cout << test() << endl;
cout << test() << endl;

return 0;
}

执行结果:




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: