Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where memory will be allocated to "Uninitialized Static variable" upon initialization?

Uninitialized static variable are always allocated in BSS. While .bss section is static as memory is allocated at compile time. As per many books "only variables that are initialized to a nonzero value occupy space" in executable. After program is loaded into memory, uninitialized static variables are still .bss.

**What happens when a function initializes it? ** Will it get moved to some other area?

like image 773
Rajesh Pal Avatar asked May 16 '26 17:05

Rajesh Pal


1 Answers

the rest of the quote:

"In the executable file, only variables that are initialized to a nonzero value occupy space."

I.E. when the executable file is loaded into memory, the needed space is allocated

like image 81
user3629249 Avatar answered May 18 '26 09:05

user3629249