当前位置:网站首页>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
边栏推荐
- 华为快应用中如何实现同时传递事件对象和自定义参数
- HDU1228 A + B(map映射)
- 2.hacking-lab脚本关[详细writeup]
- UVM——Callback
- 如何使用IDE自动签名调试鸿蒙应用
- Special topic of binary tree -- acwing 47 Path with a certain value in binary tree (preorder traversal)
- 力扣(LeetCode)182. 查找重复的电子邮箱(2022.07.01)
- 2022爱分析· 国央企数字化厂商全景报告
- OpenMLDB Meetup No.4 会议纪要
- LabVIEW为什么浮点数会丢失精度
猜你喜欢

MySQL environment configuration

VSCode工具使用

二叉树专题--AcWing 1589. 构建二叉搜索树

JSP webshell free -- webshell free

(五)APA场景搭建之挡位控制设置

【AGC】构建服务3-认证服务示例

UVM learning - build a simple UVM verification platform
![Binary tree topic -- Luogu p3884 [jloi2009] binary tree problem (DFS for binary tree depth BFS for binary tree width Dijkstra for shortest path)](/img/c2/bb85b681af0f78b380b1d179c7ea49.png)
Binary tree topic -- Luogu p3884 [jloi2009] binary tree problem (DFS for binary tree depth BFS for binary tree width Dijkstra for shortest path)
![[AI application] Hikvision ivms-4200 software installation](/img/4e/1640e3cafac13ce4d39520195c3217.png)
[AI application] Hikvision ivms-4200 software installation

Beautiful and intelligent, Haval H6 supreme+ makes Yuanxiao travel safer
随机推荐
Hdu1234 door opener and door closer (water question)
JSP webshell免杀——webshell免杀
AppGallery Connect场景化开发实战—图片存储分享
Internet News: Tencent conference application market was officially launched; Soul went to Hong Kong to submit the listing application
php中self和static在方法中的区别
从MediaRecord录像中读取H264参数
华为快应用中如何实现同时传递事件对象和自定义参数
Overview of integrated learning
二叉树专题--AcWing 47. 二叉树中和为某一值的路径(前序遍历)
JSP webshell free -- the basis of JSP
12. Process synchronization and semaphore
Session cookies and tokens
JS settimeout() and interview questions
UVM - usage of common TLM port
MySQL keyword
[TS] 1368 seconds understand typescript generic tool types!
Sus system availability scale
OpenMLDB Meetup No.4 会议纪要
华为应用市场应用统计数据问题大揭秘
QT学习日记8——资源文件添加