Is it guaranteed that first element in the below array will be set to 1
and all others to 0
, or is it compiler defined behavior?
#include <stdint.h>
int main () {
uint16_t arr[10] = {1};
}
Is it guaranteed that first element in the below array will be set to 1
and all others to 0
, or is it compiler defined behavior?
#include <stdint.h>
int main () {
uint16_t arr[10] = {1};
}
Copyright © 2021 Jogjafile Inc.
From the C Standard (6.7.9 Initialization)
and
So as the element type of your array is an arithmetic type then all elements of the array except the first element that has an explicit initializer will be zero-initialized.
Pay attention to that according to the C standard the function main without parameters shall be declared like