I am wondering if:
int a[] = {1, 2};
allocates sizeof(int) * number of constants inside brackets
int a[5] = {1, 2};
assigns constants to array fields from 0 to 1 and then fills with 0
int a[5] = {};
fills with 0
What happens when I do:
int a[] = {};
Thanks.
and
are not valid C definitions.
In GNU C (C with gcc extensions), you can use empty
{}and it is considered the same as{0}.Note that
int []is a incomplete type. When initializing an array of an incomplete type with explicit initializers, the type is completed and the number of elements of the array is then the number of elements in the brace enclosed initializer list.So
int a[] = {0};defines an array of 1 element in C and in GNU Cint a[] = {};does the same.