title: Redefinition of a pointer in global scope
body: <p>In <a href="https://stackoverflow.com/questions/21151653/why-is-setting-a-derefernce-pointer-equal-to-a-primitive-illegal">this question</a> I am thoroughly confused about this seemingly basic aspect of C. Consider these two lines of code:</p>
  
  <pre><code>int *ptr;
  *ptr = 2;
  </code></pre>
  
  <p>gcc will emit the following warnings:</p>
  
  <pre><code>main.cpp:4:1: warning: data definition has no type or storage class [enabled by default]
  
   *ptr = 2;
   ^
  main.cpp:4:2: warning: type defaults to 'int' in declaration of 'ptr' [enabled by default]
  
   *ptr = 2;
    ^
  main.cpp:4:8: warning: initialization makes pointer from integer without a cast [enabled by default]
  
   *ptr = 2;
          ^
  </code></pre>
  
  <p>What type is <code>ptr</code> being defaulted to, <code>int</code> or <code>int*</code> (as in, is <code>ptr</code> a pointer, or an <code>int</code>)? If so, does this mean that <code>ptr</code> is pointing to address 2, or is that unchanged? I would assume that it's changed because it crashes unless you give <code>ptr</code> a valid address. </p>
  
  <pre><code>int i = 5;
  int *ptr;
  *ptr = &amp;i;
  
  int main(){
      printf("%d", *ptr); // 5
  }
  </code></pre>
  
  <p>I am aware of the possibility of undefined behavior and that you shouldn't ignore warnings, but I'm trying to see what actually happens here.</p>
  
  <p>For context, see the comment chain under this <a href="https://stackoverflow.com/a/21151739/1508519">answer</a>.</p>