Linkers, Loaders & Executables
Of the global variables above, which are generally placed in the .bss section?
int a = 5;
int b;
static int c = 0;
const int d = 7;
- Aa and b
- Bb and c
- Cc and d
Show answer and explanation
Answer: B. b and c
a has a non-zero initial value, so it goes in .data; b has no initializer and starts at zero, so it goes in .bss; c is initialized to 0, so there is no need to store a zero in the file and it also goes in .bss. d is a const constant, so it goes in read-only .rodata. static decides visibility from other files; the section is determined by the initial value and const.
- A. a has the initial value 5, so it is in .data.
- B. Correct. One has no initializer and one is zero.
- C. d is a constant, so it is in .rodata.