栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

C语言关键字存储类型static

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

C语言关键字存储类型static


static 存储类
static 存储类指示编译器在程序的生命周期内保持局部变量的存在,而不需要在每次它进入和离开作用域时进行创建和销毁。因此,使用 static 修饰局部变量可以在函数调用之间保持局部变量的值。

static 修饰符也可以应用于全局变量。当 static 修饰全局变量时,会使变量的作用域限制在声明它的文件内。

全局声明的一个 static 变量或方法可以被任何函数或方法调用,只要这些方法出现在跟 static 变量或方法同一个文件中。

#include 
void func1(void);
void func2(void);
static int count=10;         
int count2=10;
int main()
{
  while (count--) {
      func1();	  
  }
  while (count2--) {
      func2();	  
  }
  return 0;
}
void func1(void)
{             
  static int thingy=5;
  thingy++;
  printf(" thingy1 为 %d , count 为 %dn", thingy, count);
}
void func2(void)
{             
  int thingy=5;
  thingy++;
  printf(" thingy2 为 %d , count 为 %dn", thingy, count2);
}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/347516.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号