title: Beginner Programmer c++(local vs global variable declaration)
body: <p>I'm new to programming. I was trying to get the sum of the equation added to the previous value when I noticed some strange behavior. </p>
  
  <p>If I declare <code>int result</code> inside <code>int main ()</code> then I get a blank answer, but if I declare <code>int result</code> outside <code>int main ()</code> then I get these values: 6,11,16...91,96,101. It doesn't make sense to me since I have no other function.</p>
  
  <p>Why does this happen?</p>
  
  <pre><code>#include&lt;iostream&gt;
  using namespace std;
  
  int main ()
  {
    int y =1;
    int result;
  
    while (result &lt;100)
    {
       result = y +5;
       cout &lt;&lt; result &lt;&lt; ",";
       y = result;
  
    }
  }
  </code></pre>