初始化C中的静态变量 [英] Initialization of static variables in C

查看:142
本文介绍了初始化C中的静态变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

C中静态变量的初始化


我知道全局变量或静态都会在C中自动初始化为零。但是,我不确定是否它们中的一个或者只有一个被初始化。
请注意,我不是讨论在函数中定义的变量,而是全局在.c文件中。

以下变量会自动初始化为零?

  static struct mystruct var1; 
struct mystruct var2;
static struct {int x; int y; } var3;


解决方案

C常见问题


Possible Duplicate:
The initialization of static variable in C

I know that either global variables or static are automatically initialized with zero in C. However, I'm not sure if both or only one of them are initialized. Note that I'm not talking about variables defined in functions but globally in the .c file.

So which of the following variables are automatically initialized with zero?

static struct mystruct var1;
struct mystruct var2;
static struct { int x; int y; } var3;

解决方案

C FAQ.

这篇关于初始化C中的静态变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆