C中的静态变量
静态变量仅初始化一次。编译器将变量保留到程序结束。静态变量可以在函数内部或外部定义。它们是本地的。静态变量的默认值为零。静态变量在程序执行之前一直有效。
这是C语言中的静态变量的语法,
static datatype variable_name = value;
这里,
datatype-变量的数据类型,例如int,char,float等。
variable_name-这是用户给定的变量名。
值-来初始化变量的任何值。默认情况下,它为零。
这是C语言中的静态变量示例,
示例
#include <stdio.h>
int main() {
auto int a = -28;
static int b = 8;
printf("The value of auto variable : %d\n", a);
printf("The value of static variable b : %d\n",b);
if(a!=0)
printf("The sum of static variable and auto variable : %d\n",(b+a));
return 0;
}输出结果
这是输出
The value of auto variable : -28 The value of static variable b : 8 The sum of static variable and auto variable : -20
热门推荐
10 祝孙辈生日祝福语简短
11 恋人跨年祝福语大全简短
12 考大学敬酒简短祝福语
13 开工投产大吉祝福语 简短
14 偶然结婚祝福语朋友简短
15 感谢学长学姐祝福语简短
16 戏精的祝福语简短
17 我要结婚祝福语简短
18 婚前女儿生日祝福语简短