title: How to initialize global variables via a function in C++
body: <p>I am learning C++. I want to have a function to initialize my variables. For example:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  double a,b
  void Initializer ( double x, double y)
  {
      a = x;   //a and b are global variables.
      b = y;
  }
  int main()
  {
      Initializer(0.,4.);
      std::cout&lt;&lt;a&lt;&lt;" "&lt;&lt;b&lt;&lt;std::endl;
      return 0;
  }
  </code></pre>
  
  <p>However, I get garbage for my global variables. For example I call <code>initializer(0.,4.)</code>, and I expect <code>a==0</code> and <code>b==4</code>; however when I print the values they are not 0,4 respectively.</p>