title: Declaring a global and a static variable
body: <p>I was studying about static variable and i came across this code on wikipedia . The static int x stores it value throughout the programme. And even when we declare it globally it will store the previous values. Does this mean static and global variables are treated as same .And if not ,how does the both work ?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
   void func() {
         static int x=0;
          // x is initialized only once across three calls of func()
          printf("%d\n", x); // outputs the value of x
          x = x + 1;
  }
  
   int main(int argc, char *argv[]) {
          func(); // prints 0
          func(); // prints 1
          func(); // prints 2
          return 0;
  }
  </code></pre>