C++ static
////main.cpp//C++Test21//#include <iostream>using namespace std;int fun(){static int mycount = 10;//在第一次进入这个函数的时候,变量a被初始化为10!并接着自减1,以后每次进入该函数return mycount--;...
·
//
// main.cpp
// C++Test21
//
#include <iostream>
using namespace std;
int fun(){
static int mycount = 10; //在第一次进入这个函数的时候,变量a被初始化为10!并接着自减1,以后每次进入该函数
return mycount--; //就不会被再次初始化了,仅进行自减1的操作;在static发明前,要达到同样的功能,则只能使用全局变量:
}
int mycount = 1;
int main(int argc, const char * argv[]) {
while(mycount <= 10){
cout << mycount << " " << fun() <<endl;
mycount++;
}
return 0;
}
//1 10
//2 9
//3 8
//4 7
//5 6
//6 5
//7 4
//8 3
//9 2
//10 1

GitCode 天启AI是一款由 GitCode 团队打造的智能助手,基于先进的LLM(大语言模型)与多智能体 Agent 技术构建,致力于为用户提供高效、智能、多模态的创作与开发支持。它不仅支持自然语言对话,还具备处理文件、生成 PPT、撰写分析报告、开发 Web 应用等多项能力,真正做到“一句话,让 Al帮你完成复杂任务”。
更多推荐
所有评论(0)