4 ms·
AFAIK only external and static variables are default initialized in C. For all other variables, the default value is undefined, so 0 is as good a choice as any
by lqet 6y ago
AFAIK only external and static variables are default initialized in C. For all other variables, the default value is undefined, so 0 is as good a choice as any other here.
- DC-3 6y agoExcept that uninitialised memory is substantially more likely to be 0 than any other value.
- grishka 6y agoExcept sometimes it is not and forgetting to initialize a variable in C/C++ leads to very insidious bugs that no one can reliably reproduce.
- kevincox 6y agoThat's not quite true. While it is undefined 0 is a fairly common value for memory and registers meaning that your "undefined" values is likely 0 a higher than average amount of the time.
- anonymousiam 6y agoThere is also the issue that (at least on some platforms) ECC memory must be initialized before being read, or an exception will occur.
- fnord77 6y agoif you use malloc, yes. calloc will initialize the variables