C语言中int类型直接初始化与结构体中区别

#include <stdio.h>

#define ListSize 100

typedef int DataType;
typedef struct {
    DataType data[ListSize];
    int length;
} SeqList;

int main()
{
    SeqList L;
    int a;
    printf("%d\n", L.length);
    printf("%d\n", a);
    return 0;
}

输出结果

253673526
0

为什么?

阅读 2k
1 个回答

都是随机值。你碰巧随机到了这两个值而已。

C11 draft N1570

6.7.9 Initialization

10 If an object that has automatic storage duration is not initialized explicitly, its value is
indeterminate. ...

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进