How this works(sets all values to 0)?
int array[28]= {0};
and why this not works(does not set all values to 4 but only the first value sets to 4 and others to 0)?
int array[28]= {4};
The elements which are not initialized are set 0. In your first case you are initilizing it by providing it the value as 0 and rest are by default initialized as 0. In your second case the first values is intialized with 4 and rest as 0. The standard says:
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With