Possible Duplicate:
Does gcc automatically initialize static variables to zero?
Are statically declared objects inside a function guaranteed to be initialized with 0
?
For example:
int func(void)
{
static int x;
...
}
Does the standard promise that x = 0
upon the first invocation of func()
?
The C99 Standard says:
5.1.2 Execution environments
... All objects in static storage shall be initialized (set to their initial values) before program startup.
And it also says that a local variable defined with static
qualifier has "static storage" and that in the absence of an initialization all objects take the value 0 of the right type for them.
That's right. For more insight you can refer to exact same question asked a while ago here:
Does gcc automatically initialize static variables to zero?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With