If you define an object with an initializer, it's initialized to the specified value. If you only specify values for some members, the others are initialized to zero (meaning 0
for integers (including characters), 0.0
for floating-point values, and NULL
for pointers).
If you define an object without an initializer, all members are implicitly initialized to zero if the object has static storage duration, i.e., if it's defined outside any function or if it's defined with the static
keyword.
An object defined inside a function without the static
keyword has automatic storage duration. Such objects, if not explicitly initialized, start off with garbage values. (If you happen to see such objects seemingly initialized to zero, remember that zero can be just as much a garbage value as anything else.)
You asked:
Are the integer fields (number and year) initialized to 0 by default
when the other char fields are initialized but not these two?
but the code in your question doesn't initialize the char[]
fields. See pmg's answer, which shows some good examples, but doesn't currently mention the static
vs. automatic distinction.