All the initialized global/static variables will go to initialized data section.
All the uninitialized global/static variables will go to uninitialed data section(BSS). The variables in BSS will get a value 0 during program load time.
If a global variable is explicitly initialized to zero (int myglobal = 0), where that variable will be stored?
Compiler is free to put such variable into
bssas well as intodata. For example, GCC has a special option controlling such behavior:Tried with the following example (
test.cfile):Compiling with no options (implicitly
-fzero-initialized-in-bss):Compiling with
-fno-zero-initialized-in-bssoption: