当前位置:网站首页>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
边栏推荐
- 二叉树专题--AcWing 3540. 二叉搜索树建树(实用板子 构建二叉搜索树 并输出前、中、后序遍历)
- static 函数中的静态变量
- Hdu1236 ranking (structure Sorting)
- 12. Process synchronization and semaphore
- Win11 arm系统配置.net core环境变量
- Special topic of binary tree -- acwing 3540 Binary search tree building (use the board to build a binary search tree and output the pre -, middle -, and post sequence traversal)
- LeetCode+ 76 - 80 暴搜专题
- 集成学习概览
- JVM garbage collector
- 二叉树专题--AcWing 1497. 树的遍历(利用后、中序遍历,构建二叉树)
猜你喜欢

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

从.bag文件中读取并保存.jpg图片和.pcd点云

UVM learning - build a simple UVM verification platform

Common methods of JS array

4. Random variables

axis设备的rtsp setup头中的url不能带参

Hdu1228 a + B (map mapping)
![[visual studio] visual studio 2019 community version cmake development environment installation (download | install relevant components | create compilation execution project | error handling)](/img/9f/4265f1e3927fcf66602f0fc9e7a9d9.jpg)
[visual studio] visual studio 2019 community version cmake development environment installation (download | install relevant components | create compilation execution project | error handling)

Kustomize使用手册

From Read and save in bag file Jpg pictures and PCD point cloud
随机推荐
LabVIEW为什么浮点数会丢失精度
Shapiro Wilk normal analysis by SPSS
[SUCTF2018]followme
Special topic of binary tree -- acwing 18 Rebuild the binary tree (construct the binary tree by traversing the front and middle order)
js数组常用方法
二叉树专题--AcWing 19. 二叉树的下一个节点(找树中节点的后继)
2022-06-17
P1055 [noip2008 popularization group] ISBN number
计算序列之和
全网显示 IP 归属地,是怎么实现的?
1287_FreeRTOS中prvTaskIsTaskSuspended()接口实现分析
2022-06-17
记录 AttributeError: ‘NoneType‘ object has no attribute ‘nextcall‘
PCL point cloud to depth image
如何用list组件实现tabbar标题栏
UWA报告使用小技巧,你get了吗?(第四弹)
2. Hacking lab script off [detailed writeup]
PCL 从一个点云中提取一个子集
Is the account above changtou school safe?
【AppLinking实战案例】通过AppLinking分享应用内图片