Is this undefined behavior and how would you tell?
<p>Motivated by answers to this post. <a href="http://stackoverflow.com/questions/15819836/why-is-this-nan">Why is this NaN</a></p>

<p>I have the following code:</p>

<pre><code>int main()
{
   const int weeks = 10;
   const int salespersons = 9;
   const int days = 30;

   double weekly_sales[weeks][salespersons][days];
   double total_weekly_sales[weeks];
   double total_overall_weekly_sales[salespersons];
   int a;
   cout &lt;&lt; "a = " &lt;&lt; a &lt;&lt;endl;
   cout &lt;&lt; total_weekly_sales[0] &lt;&lt;endl; 
   for(int w=0; w &lt; weeks;w++)
   {
      for(int d =0; d &lt; days; d++)
      {  
          for(int s=0; s &lt; salespersons; s++)
          {
              total_weekly_sales[w]+=weekly_sales[w][s][d];
              total_overall_weekly_sales[s]+= weekly_sales[w][s][d];
          }
       }  
    }
 cout &lt;&lt; total_weekly_sales[0] &lt;&lt;endl;
}
</code></pre>

<p>It will output the following:</p>

<pre><code>a = 0
0
0
</code></pre>

<p>Under gcc 4.5.3, with compiling option <code>-Wall</code>.</p>

<p>I also compiled the code under here: <a href="http://liveworkspace.org/code/94SOj" rel="nofollow">http://liveworkspace.org/code/94SOj</a>$2. Same output as above.</p>

<p>I also compiled the code under VS2010.
VS2010 gaves warning as follows:</p>

<pre><code>warning C4700: uninitialized local variable 'a' used
warning C4700: uninitialized local variable 'total_weekly_sales' used
</code></pre>

<p>When I ran:</p>

<pre><code>Run-Time Check Failure #3 - The variable 'a' is being used without being initialized.
</code></pre>

<p>I know that it is bad practice to NOT initialize local variable and use them. I also understand it will be problematic.</p>

<p>My question is:</p>

<p>In C++ standard: is there any place saying that using uninitialized local variable will result in undefined behavior? Why does it behave differently under different compilers? Does this mean the standard actually does not enforce that all compilers should implement proper actions regarding <code>using uninitialized local variable</code>? How would you tell it is undefined behavior from compiler output then?</p>

<p>Thanks.</p>
