当前位置:网站首页>Static variables in static function
Static variables in static function
2022-07-02 10:59:00 【luoganttcc】
Static variables in functions
When a variable is declared as static when , Space will be allocated throughout the life cycle of the program . Even if the function is called multiple times , The space of static variables is allocated only once , The value of the variable in the previous call is passed through the next function call . This is true of C / C ++ Or any other application that needs to store the state of a previous function .
#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;
}
Output :
0 1 2 3 4
边栏推荐
猜你喜欢
Special topic of binary tree -- acwing 1589 Building binary search tree
HDU1236 排名(结构体排序)
[TS] 1368 seconds understand typescript generic tool types!
2. Hacking lab script off [detailed writeup]
QT学习日记8——资源文件添加
如何用list组件实现tabbar标题栏
从MediaRecord录像中读取H264参数
V2X-Sim数据集(上海交大&纽约大学)
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
二叉树专题--洛谷 P1229 遍历问题(乘法原理 已知前、后序遍历求中序遍历个数)
随机推荐
13. Semaphore critical zone protection
2. Hacking lab script off [detailed writeup]
UWA报告使用小技巧,你get了吗?(第四弹)
In the face of uncertainty, the role of supply chain
From Read and save in bag file Jpg pictures and PCD point cloud
LabVIEW为什么浮点数会丢失精度
Oracle 笔记
Special topic of binary tree -- acwing 3384 Binary tree traversal (known preorder traversal, while building a tree, while outputting middle order traversal)
【付费推广】常见问题合集,推荐榜单FAQ
K-d tree and octree of PCL
Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
(5) Gear control setting of APA scene construction
2022爱分析· 国央企数字化厂商全景报告
Nodejs+express+mysql simple blog building
2022-06-17
MySQL lethal serial question 3 -- are you familiar with MySQL locks?
Hdu1228 a + B (map mapping)
PCL projection point cloud
Special topic of binary tree -- acwing 1589 Building binary search tree
洛谷 P1892 [BOI2003]团伙(并查集变种 反集)