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
热门推荐
1 训练狗狗基础
2 怎么训练狗狗笑
3 怎么训练狗狗卧下
4 上海狗狗训练基地
5 训练狗狗排便
6 狗狗基础训练
8 如何训练狗狗装死
9 狗狗站姿训练
10 狗狗训练用品
11 训练狗狗吧
12 狗狗要怎么训练
13 怎么训练狗狗玩球
14 训练狗狗唤回
15 狗狗训练躺下
16 狗狗训练指令
17 狗狗的训练技巧
18 狗狗不好训练