In C programming, when a program executed, all the data which are used in program will be placed in different sections. I know that the global and staic variables which are not initialized are stored in the .bss section. And all the global and static variables which are initialized are stored in data segment. If data segment is already present, then what is the purpose of using .bss?
2 Answers
To quote Wikipedia:
Typically only the length of the bss section, but no data, is stored in the object file. The program loader allocates and initializes memory for the bss section when it loads the program. Operating systems may use a technique called zero-fill-on-demand to efficiently implement the bss segment (McKusick & Karels 1986). In embedded software, the bss segment is mapped into memory that is initialized to zero by the C run-time system before main() is entered.
So it's a quick and easy way of initializing a group of variables to zero rather than take up space in the program image explicitly setting them to zero.

- 60,939
- 11
- 97
- 136
During C-runtime initialization, .bss and .data are often handled differently.
On some systems, the .data section is initialized from a compressed data-set, where as .bss is simply set to zero
So in other words, handling un-initialized data, and initialized data can be useful.

- 5,100
- 5
- 32
- 50