title: Extern in multiple files and possible double definition
body: <p>I was running the following codes compiled together as: <code>gcc A.c B.c -o combined</code></p>
  
  <p>Program A:</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  int a=1;
  int b;
  int main()
  {
  extern int a,b;
  fun();
  printf("%d %d\n",a,b);
  }
  </code></pre>
  
  <p>Program B: </p>
  
  <pre><code>int a;
  int b=2;
  int fun()
  {
  printf("%d %d\n",a,b); 
  return 0;
  }
  </code></pre>
  
  <p>On running the "combined" program the output was: </p>
  
  <pre><code>1 2
  1 2
  </code></pre>
  
  <p>Now, I've a few doubts about this one:</p>
  
  <ol>
  <li><p>Why isn't the output:</p>
  
  <p>0 2</p>
  
  <p>1 0</p></li>
  <li><p>Aren't a and b defined twice?</p></li>
  </ol>
  
  <p>Please explain these clearly, I've had a lot of problems understanding extern and few of these doubts keep coming from time to time.</p>
  
  <p>Thanks in Advance.</p>