From the C Standard (6.7.9 Initialization)
10 If an object that has automatic storage duration is not initialized
explicitly, its value is indeterminate. If an object that has static
or thread 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, and any padding is initialized to zero bits;
— if it is a union, the first named member is initialized
(recursively) according to these rules, and any padding is initialized
to zero bits;
and
19 ... all subobjects that are not initialized explicitly shall be
initialized implicitly the same as objects that have static storage
duration.
Thus in this program
#include <stdio.h>
int main(void) {
int memo[1000];
for (int i = 0; i < 1000; i++) {
printf("%d\t", memo[i]);
}
return 0;
}
the array memo
has the automatic storage duration and according to the provided quote from the C Standard its elements have indeterminate values.
You could declare the array like
int memo[1000] = { 0 };
In this case the first element of the array is explicitly initialized by 0 and all other elements are implicitly initialized also by 0.
You could select any element of the array to be explicitly initialized like for example
int memo[1000] = { [999] = 0 };
If you would write
#include <stdio.h>
int memo[1000];
int main(void) {
for (int i = 0; i < 1000; i++) {
printf("%d\t", memo[i]);
}
return 0;
}
or
#include <stdio.h>
int main(void) {
static int memo[1000];
for (int i = 0; i < 1000; i++) {
printf("%d\t", memo[i]);
}
return 0;
}
then elements of the array will be zero-initialized because a variable declared in a file scope or with the storage specifier static
has the static storage duration.