c - Is providing more initializers in an array initializer list than there are elements in the array a syntax error? -
i told true (in pearson book how program), when compiling inside ide of netbeans,
the following function code
int n[5] = {6, 5, 4, 3, 2, 1, 2, 3, 2};
does not result in compile time error cause unexpected behavior further in program. accessing locations in array shouldn't exist not cause syntax error.
printf("%d", n[7]);
am missing something?
yes code wrong:
int n[5] = {6, 5, 4, 3, 2, 1, 2, 3, 2};
per 6.7.9 initialization, paragraph 2 of the c standard:
constraints
no initializer shall attempt provide value object not contained within entity being initialized.
as noted in comments, constraint violation , semantic error must reported compiler. i'd compiler fails report error deficient.
Comments
Post a Comment