Are c struct members guaranteed to be initialized to 0?

When I declare a structure in C, am I sure that the members will be initialized with some specific value, like 0 for integer members?

EDIT:

So, let's say I have a structure that looks like this:

typedef struct
{
     int a;
} my_str;

and I declare:

my_str thing1;

worldwide. According to some answers thing1.a will be initialized to 0 - do I understand this correctly?

+3
source share
6 answers

Relevant parts of C99 standard:

section 6.2.4, ยง3:

, , static . - , , .

6.2.4, ยง4:

, static- .

6.2.4, ยง5 ( ):

. , , ; , .

6.7.8, ยง10:

, , . , , :

- , ;

- type, ( ) ;

- , () ;

- , () .

+7

, ( , ) 0. .

+7

ANSI C standard: , , , , 0, , . , ,

+1

++ .

- , . . , struct . , . , static , .

0

.

, MS V++ .

-1

. . , , , โ€‹โ€‹.

EDIT: Yes, I forgot to mention the static variables inside the function.

-1
source

Source: https://habr.com/ru/post/1719026/


All Articles