当前位置:网站首页>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
边栏推荐
- Win11 arm系统配置.net core环境变量
- 618 what is the secret of dominating the list again? Nike's latest financial report gives the answer
- SPSS做Shapiro-Wilk正态分析
- 学习open62541 --- [66] UA_String的生成方法
- 【快应用】text组件里的文字很多,旁边的div样式会被拉伸如何解决
- 《MySQL 8 DBA基础教程》简介
- 简洁、快速、节约内存的Excel处理工具EasyExcel
- 互联网快讯:腾讯会议应用市场正式上线;Soul赴港递交上市申请书
- Internet News: Tencent conference application market was officially launched; Soul went to Hong Kong to submit the listing application
- MongoDB-快速上手MongoDB命令行的一些简单操作
猜你喜欢
随机推荐
【快应用】text组件里的文字很多,旁边的div样式会被拉伸如何解决
JSP webshell免杀——webshell免杀
全网显示 IP 归属地,是怎么实现的?
Hdu1234 door opener and door closer (water question)
session-cookie与token
点云投影图片
长投学堂上面的账户安全吗?
How to get the password of cpolar?
MySQL lethal serial question 3 -- are you familiar with MySQL locks?
Shell programming 01_ Shell foundation
JS settimeout() and interview questions
618 what is the secret of dominating the list again? Nike's latest financial report gives the answer
4.随机变量
"Matching" is true love, a new attitude for young people to make friends
Win11 arm系统配置.net core环境变量
Transport Optimization abstraction
STM32 and motor development (upper system)
13. Semaphore critical zone protection
[SUCTF2018]followme
拆解美图SaaS:开着飞机换引擎