Linkers, Loaders & Executables
In C, a global variable written outside any function as "int limit = 100;" is generally placed in which section?
- A.data (initialized data)
- B.bss (uninitialized data)
- C.text (machine code)
Show answer and explanation
Answer: A. .data (initialized data)
Global and static variables with a non-zero initial value go in the .data section, and their initial values are stored in the file. When the program is loaded, this content is copied into memory as is, so limit is already 100 when main starts. Because .data is modified at run time, it is mapped readable and writable.
- A. Correct. The file holds the initial value 100.
- B. .bss is for variables that are zero or have no initializer.
- C. .text is for code.