This is standard behavior. Every element of an array that is not explicitly initialized is initialized to a default value ('\0'
for char
), if any prefix of the array is initialized in the declaration. It also works for other types:
int a[10] = {1};
zeroes out a[1]
through a[9]
.