title: Storage of global variables in recursive function calls in memory
body: <p>In recursive functions the local variables in each recursive function call are stored in a stack but what happens if I declare a global variable and use it in the recursive function? How are  global variables handled?</p>
  
  <p>The usual code for an factorial is </p>
  
  <pre><code>int fact (int n)
  {
    if(n&lt;1) return 1;
        else return (n*fact(n-1));
  }
  </code></pre>
  
  <p>While i was reading computer architecture,i studied that local variables are stored in a stack from a higher addresses to lower addresses,heap is for dynamic structures which start from lower addresses and global variables are stored separately.</p>
  
  <p>so i modified it to </p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  
  int global=0;
  
  int fact()
  {
    if(global&lt;1)return 1;
    else
        return((global--)*fact());
  }
  
  main()
  {
    int i=0;
    printf("enter the factorial\n");
    scanf("%d",&amp;global);
    i=fact();
    printf("%d\n",i);
  } 
  </code></pre>
  
  <p>I know something the code is wrong intuitively ,i just modified it to this to check whats gonna happen.the result is segmentation fault Please explain me whats happening here,possibly how the compiler behaves to this? </p>