当前位置:网站首页>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
边栏推荐
猜你喜欢

14. Code implementation of semaphore
![2.hacking-lab脚本关[详细writeup]](/img/f3/29745761cd5ad4df84c78ac904ea51.png)
2.hacking-lab脚本关[详细writeup]

Mysql database remote access permission settings

华为AppLinking中统一链接的创建和使用

Read H264 parameters from mediarecord recording

Retrofit's callback hell is really vulnerable in kotlin synergy mode!

MYSQL环境配置

UVM learning - object attribute of UVM phase

AI技术产业热点分析

Operator-1 first acquaintance with operator
随机推荐
长投学堂上面的账户安全吗?
Transport Optimization abstraction
Open the encrypted SQLite method with sqlcipher
互联网快讯:腾讯会议应用市场正式上线;Soul赴港递交上市申请书
Pywin32 opens the specified window
集成学习概览
UVM - usage of common TLM port
Pywin32打开指定窗口
[SUCTF2018]followme
SQOOP 1.4.6 INSTALL
MySQL lethal serial question 4 -- are you familiar with MySQL logs?
LabVIEW为什么浮点数会丢失精度
02-taildir source
LeetCode+ 76 - 80 暴搜专题
Use WinDbg to statically analyze dump files (summary of practical experience)
P1055 [NOIP2008 普及组] ISBN 号码
UVM learning - object attribute of UVM phase
Disassembling Meitu SaaS: driving the plane to change the engine
Convert yv12 to rgb565 image conversion, with YUV to RGB test
华为AppLinking中统一链接的创建和使用