Initialization of static variables in C [duplicate]

佐手、 提交于 2019-12-04 16:29:47
Asim Ihsan

I ran the following code in codepad

struct mystruct { int a; };

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

#include <stdio.h>
void main()
{
    int x;
    printf("var1.a: %d\n", var1.a);
    printf("var2.a: %d\n", var2.a);
    printf("var3.x: %d\n", var3.x);
    printf("var3.y: %d\n", var3.y);
    printf("x: %d\n", x);
}

results:

var1.a: 0
var2.a: 0
var3.x: 0
var3.y: 0
x: 1075105060

Regardless, I don't like making assumptions about initialisation but YMMV.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!