title: How are global variables stored?
body: <p>AFAIK, there're 2 types of global variables, <em>initialized</em> and <em>unintialized</em>. How are they stored? Are they both stored in the executable file? I can think of initialized global variables having their initial values stored in executable file. But what needs to be stored for the uninitialized ones?</p>
  
  <p>My current understanding is like this:</p>
  
  <p>Executable file is organized as several sections, such as .text, .data, and .bss. Code is stored in .text section, initialized global or static data is stored in .data section, and uninitialized global or static data is stored in .bss section.</p>
  
  <p>Thanks for your time to view my questions.</p>
  
  <h2>Update 1 - 9:56 AM 11/3/2010</h2>
  
  <p>I found a good reference here: </p>
  
  <p><a href="http://www.enchantedlearning.com/sparc/segments/segmentsassembly.shtml" rel="nofollow">Segments in Assembly Language Source - 
  Building the text and data segments with .text, .data, and .bss directives</a></p>
  
  <h2>Update 2 - 10:09 AM 11/3/2010</h2>
  
  <p>@Michael</p>
  
  <ol>
  <li><p>I define a 100 bytes of un-initialized data area in my assembly code, this 100-bytes is not stored in my executable file because it is NOT initialized.</p></li>
  <li><p>Who will allocate the 100-byte uninitialized memory space in RAM? The <em>program loader</em>?</p></li>
  </ol>
  
  <p>Suppose I got the following code:</p>
  
  <pre><code>int global[100];
  
  void main(void)
  {
     //...
  }
  </code></pre>
  
  <p>The global[100] is not initialzed. How will the global[100] be recoded in my executable file? And who will allocate it at what time? What if it is initialized?</p>