当前位置:网站首页>static 函数中的静态变量
static 函数中的静态变量
2022-07-02 07:19:00 【luoganttcc】
函数中的静态变量
当变量声明为static时,空间将在程序的生命周期内分配。即使多次调用该函数,静态变量的空间也只分配一次,前一次调用中的变量值通过下一次函数调用传递。这对于在C / C ++或需要存储先前函数状态的任何其他应用程序非常有用。
#include <iostream>
#include <string>
using namespace std;
void demo()
{
// static variable
static int count = 0;
cout << count << " ";
// value is updated and
// will be carried to next
// function calls
count++;
}
int main()
{
for (int i=0; i<5; i++)
demo();
return 0;
}
输出:
0 1 2 3 4
边栏推荐
- JSP webshell免杀——JSP的基础
- 14. Code implementation of semaphore
- 12. Process synchronization and semaphore
- Solution of mysql8 forgetting password file in Windows Environment
- 01 install virtual machine
- The URL in the RTSP setup header of the axis device cannot take a parameter
- MySQL数据库远程访问权限设置
- 使用Windbg静态分析dump文件(实战经验总结)
- js setTimeout()与面试题
- 02-taildir source
猜你喜欢
随机推荐
Hdu1228 a + B (map mapping)
6种单例模式的实现方式
AppGallery Connect场景化开发实战—图片存储分享
4.随机变量
JSP webshell免杀——JSP的基础
Solution of mysql8 forgetting password file in Windows Environment
首份中国企业敏捷实践白皮书发布| 附完整下载
What are the popular frameworks for swoole in 2022?
2. Hacking lab script off [detailed writeup]
大华设备播放过程中设置播放速度
对话吴纲:我为什么笃信“大国品牌”的崛起?
正则及常用公式
最详细MySql安装教程
长投学堂上面的账户安全吗?
Windows环境MySQL8忘记密码文件解决方案
Importing tables from sqoop
MySQL lethal serial question 4 -- are you familiar with MySQL logs?
MongoDB 学习整理(条件操作符,$type 操作符,limit()方法,skip() 方法 和 sort() 方法)
MySQL environment configuration
UVM - configuration mechanism









![2. Hacking lab script off [detailed writeup]](/img/f3/29745761cd5ad4df84c78ac904ea51.png)