Вход на сайт
Тупой вопрос по С: инитиализация структуры
660 просмотров
Перейти к просмотру всей ветки
scorpi_ постоялец
в ответ rahimov80 12.06.09 16:56, Последний раз изменено 17.06.09 21:35 (scorpi_)
В ответ на:
А если у меня есть структура и я указал
А если у меня есть структура и я указал
struct myStr {
int a;
int b;
char* c;
} myStrVar = {0};
то какое значение будет у myStrVar.b; myStrVar.c ? Обнулится ли?
Да, обнулится:
В ответ на:
C99 (ISO/IEC 9899:1999) - 6.7.8 Initialization - 21
If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration.
C99 (ISO/IEC 9899:1999) - 6.7.8 Initialization - 21
If there are fewer initializers in a brace-enclosed list than there are elements or members of an aggregate, or fewer characters in a string literal used to initialize an array of known size than there are elements in the array, the remainder of the aggregate shall be initialized implicitly the same as objects that have static storage duration.
В ответ на:
C99 (ISO/IEC 9899:1999) - 6.7.8 Initialization - 10
If an object that has automatic storage duration is not initialized explicitly, its value is indeterminate. If an object that has static storage duration is not initialized explicitly, then:
- if it has pointer type, it is initialized to a null pointer;
- if it has arithmetic type, it is initialized to (positive or unsigned) zero;
- if it is an aggregate, every member is initialized (recursively) according to these rules;
- if it is a union, the first named member is initialized (recursively) according to these rules.
C99 (ISO/IEC 9899:1999) - 6.7.8 Initialization - 10
If an object that has automatic storage duration is not initialized explicitly, its value is indeterminate. If an object that has static storage duration is not initialized explicitly, then:
- if it has pointer type, it is initialized to a null pointer;
- if it has arithmetic type, it is initialized to (positive or unsigned) zero;
- if it is an aggregate, every member is initialized (recursively) according to these rules;
- if it is a union, the first named member is initialized (recursively) according to these rules.