当前位置:网站首页>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
边栏推荐
- Hdu1236 ranking (structure Sorting)
- stm32和電機開發(上比特系統)
- 最详细MySql安装教程
- VSCode工具使用
- session-cookie与token
- Retrofit's callback hell is really vulnerable in kotlin synergy mode!
- Transport Optimization abstraction
- 2. Hacking lab script off [detailed writeup]
- Ks009 implement pet management system based on SSH
- Record attributeerror: 'nonetype' object has no attribute 'nextcall‘
猜你喜欢

Dialogue Wu Gang: why do I believe in the rise of "big country brands"?

Internet News: Tencent conference application market was officially launched; Soul went to Hong Kong to submit the listing application

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

Flutter——Canvas自定义曲线图

Flink submitter

Solutions to a series of problems in sqoop job creation

Jsp webshell Free from killing - The Foundation of JSP

Ks009 implement pet management system based on SSH

一招快速实现自定义快应用titlebar

Thanos Receiver
随机推荐
【TS】1368- 秒懂 TypeScript 泛型工具类型!
Windows环境MySQL8忘记密码文件解决方案
PCL Eigen介绍及简单使用
Shutter - canvas custom graph
02-taildir source
使用华为性能管理服务,按需配置采样率
MongoDB 学习整理(条件操作符,$type 操作符,limit()方法,skip() 方法 和 sort() 方法)
Thanos Receiver
P1055 [noip2008 popularization group] ISBN number
AppGallery Connect场景化开发实战—图片存储分享
What is the significance of the college entrance examination
2022-06-17
Disassembling Meitu SaaS: driving the plane to change the engine
The nanny level tutorial of flutter environment configuration makes the doctor green to the end
Oracle notes
MySQL数据库远程访问权限设置
4.随机变量
UVM factory mechanism
AttributeError: type object ‘Image‘ has no attribute ‘fromarray‘
学习open62541 --- [66] UA_String的生成方法