A quick test shows a and c to be 0.
int a;
static int c;
int main() {
printf("%d %d\n", a, c);
return 0;
}
The location of a (and c) are determined at compile-time; that is, they're neither put on the stack nor in a memory interval returned by malloc. I think the C standard says they're initialized to 0 in all cases, then.
I'm 99.9% confident about with respect to c
, and 98% confident with regard to a
. The keyword static
, in the context of global variables, really is analogous to private
in (say) C++ and Java: it's about visibility, not storage location.
What Andrew Hare says about uninitialized variables is true for data stored on the stack or in malloc'd memory. Not so for statically stored variables.