Linkers, Loaders & Executables

In C, a global variable written outside any function as "int limit = 100;" is generally placed in which section?

  1. A.data (initialized data)
  2. B.bss (uninitialized data)
  3. 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.
Practice this topic Back to topic

More Linkers, Loaders & Executables questions

  1. What is a characteristic of the .bss section?
  2. Running C code "char *p = "hello"; p[0] = 'H';" crashes in many environments. Why?
  3. Of the global variables above, which are generally placed in the .bss section?
  4. Where is a non-static local (automatic) variable declared inside a C function placed at run time?
  5. Memory allocated with C's malloc generally comes from which area of a process?