title: Difference between data section and the bss section in C
body: <p>When checking the disassembly of the object file through the readelf, I see the data and the bss segments contain the same offset address.
  The data section will contain the initialised global and static variables. BSS will contain un-initialised global and static variables.</p>
  
  <pre><code>  1 #include&lt;stdio.h&gt;
    2 
    3 static void display(int i, int* ptr);
    4 
    5 int main(){
    6  int x = 5;
    7  int* xptr = &amp;x;
    8  printf("\n In main() program! \n");
    9  printf("\n x address : 0x%x x value : %d  \n",(unsigned int)&amp;x,x);
   10  printf("\n xptr points to : 0x%x xptr value : %d \n",(unsigned int)xptr,*xptr);
   11  display(x,xptr);
   12  return 0;
   13 }
   14 
   15 void display(int y,int* yptr){
   16  char var[7] = "ABCDEF";
   17  printf("\n In display() function  \n");
   18  printf("\n y value : %d y address : 0x%x  \n",y,(unsigned int)&amp;y);
   19  printf("\n yptr points to : 0x%x yptr value : %d  \n",(unsigned int)yptr,*yptr);
   20 }
  </code></pre>
  
  <p>output: </p>
  
  <pre><code>   SSS:~$ size a.out 
     text    data     bss     dec     hex filename
     1311     260       8    1579     62b a.out
  </code></pre>
  
  <p>Here in the above program I don't have any un-initialised data but the BSS has occupied 8 bytes. Why does it occupy 8 bytes?
  Also when I disassemble the object file,</p>
  
  <blockquote>
    <p>EDITED :</p>
  </blockquote>
  
  <pre><code>  [ 3] .data             PROGBITS        00000000 000110 000000 00  WA  0   0  4
    [ 4] .bss              NOBITS          00000000 000110 000000 00  WA  0   0  4
    [ 5] .rodata           PROGBITS        00000000 000110 0000cf 00   A  0   0  4
  </code></pre>
  
  <p>data, rodata and bss has the same offset address. Does it mean the rodata, data and bss refer to the same address? 
  Do Data section, rodata section and the bss section contain the data values in the same address, if so how to distinguish the data section, bss section and rodata section?</p>