Are the members of a global structure initialized to zero by default in C?

后端 未结 5 1769
星月不相逢
星月不相逢 2020-12-04 22:21

Are the members of a global or static structure in C guaranteed to be automatically initialized to zero, in the same way that uninitialized global or static variables are?

5条回答
  •  醉梦人生
    2020-12-04 22:39

    All data in global part of the program is set to zero.

    The BSS segment also known as Uninitialized data starts at the end of the data segment and contains all uninitialized global variables and static variables that are initialized to zero by default. For instance a variable declared static int i; would be contained in the BSS segment.

    Bss segment.

    I don't know why is it so hard to try it yourself btw.

提交回复
热议问题