title: declaration of variables with same name as global,local and static
body: <p>I have the following code snippet and I have to analyse what the output will be:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
    void f(int d);
  
    int a = 1, b = 2, c = 3, d = 4;
  
    int main(){
      int a = 5, c = 6;
      f(a);
      f(b);
      f(c);
      printf("%d %d %d %d\n",a,b,c,d);
      return 0;
    }
  
    void f(int d){
      static int a = 0;
      a = a + 7;
      b = a + d;
      c++;
      d--;
      printf("%d %d %d %d\n",a,b,c,d);
    }
  </code></pre>
  
  <p>The output I've got is as follows:</p>
  
  <pre><code>7 12 4 4  
  15 26 5 11  
  21 27 6 5  
  5 27 6 4  
  </code></pre>
  
  <p>This really baffled me. I noticed that in all 3 function calls the globally declared <code>a</code> suffers the assignment and that in the <code>printf()</code> from <code>main()</code> body the <code>a</code> declared in <code>main()</code> is printed. However, I am not sure about the behaviour of the rest of the variables. Is this undefined behaviour or it actually makes sense?</p>