title: Why do I get "error undeclared identifier" unless I declare my variable at the beginning?
body: <p>When I have following:</p>
  
  <pre><code>#include "stdafx.h"
  #include&lt;stdio.h&gt;
  int main()
  {
  
  int val1,val2;
  
  printf("Enter the first value");
  scanf("%d",val1);
  scanf("%d",&amp;val2);
  int c;
  c=val1 + val2;
  printf(" the value is : %d", c);
  
  
  
  return 0; // 0 means no error
  
   }
  </code></pre>
  
  <p>I get error undeclared identifier c. Also, syntax error. missing ; before type.</p>
  
  <p>However, if I change above to following error disappears. Please help</p>
  
  <pre><code>#include "stdafx.h"
  #include&lt;stdio.h&gt;
  
  int main()
  {
  
  int val1,val2,c;
  
  printf("Enter the first value");
  scanf("%d",&amp;val1);
  scanf("%d",&amp;val2);
  
  c=val1 + val2;
  printf(" the value is : %d", c);
  
  
  
  return 0; // 0 means no error
  
  }
  </code></pre>
  
  <p>I am running C in VS 2010.</p>