Static variables in memory
Filed under Synopsys
Free read 2 of 3The Data segment stores initialized global and static variables. The BSS (Block Started by Symbol) segment stores uninitialized global and static variables.
The question
Explain the memory layout of static variables in C/C++ and the difference between the Data segment and BSS segment.
Constraints
- Focus on compiled languages like C/C++.
- Explain initialization behavior.
Approach
The Data segment stores initialized global and static variables. The BSS (Block Started by Symbol) segment stores uninitialized global and static variables.
BSS variables are zero-initialized by the OS at program startup, whereas Data segment variables are initialized with specific values from the binary.
Static variables persist for the entire duration of the program execution, regardless of the scope in which they are declared.
Tips
- What they are testing: Be prepared to discuss how static variables differ from global variables in terms of scope.
- Common mistake: Confusing the stack/heap with static memory segments.
Related Synopsys questions
Collected from public candidate posts and coding forums. Updated Nov 2026.