title: When are static and global variables initialized?
body: <p>In <code>C++</code> I know <code>static</code> and <code>global</code> objects are constructed before the <code>main</code> function. But as you know, in <code>C</code>, there is no such kind <code>initialization procedure</code> before <code>main</code>.</p>
  
  <p>For example, in my code:</p>
  
  <pre><code>int global_int1 = 5;
  int global_int2;
  static int static_int1 = 4;
  static int static_int2;
  </code></pre>
  
  <ul>
  <li>When are these four variables <strong>initialized</strong>?</li>
  <li>Where values for initialization like <code>5</code> and <code>4</code> are stored during compilation? How to manage them when initialization?</li>
  </ul>
  
  <hr>
  
  <p><em>EDIT:</em><br>
  Clarification of 2nd question.  </p>
  
  <ul>
  <li>In my code I use <code>5</code> to <strong>initialize</strong> <code>global_int1</code>, so how can the compiler <strong>assign</strong> <code>5</code> to <code>global_int</code>? For example, maybe the compiler first store the <code>5</code> value at somewhere (i.e. a table), and get this value when initialization begins.</li>
  <li>As to "How to manage them when initialization?", it is realy vague and I myself does not how to interpret yet. Sometimes, it is not easy to explain a question. Overlook it since I have not mastered the question fully yet.</li>
  </ul>