title: Updating a global variable in C
body: <p>I have a beginners C question. I want in the code below...</p>
  
  <pre><code>include &lt;stdio.h&gt;
  
  void iprint();
  int i=0;
  
  int main()
  {
    int j;
  
    for (j=0; j&lt;50; j++)
      {
        iprint(i);
        printf("%d\n",i);
      }
  }
  
  void iprint(i)
  {
    i +=1;
    //printf("%d\n",i); 
  }
  </code></pre>
  
  <p>... the function "iprint" to update the value of i each time is it called, e.g. update i so that it can be used in main with the value 1 for iteration 2, and 3 for iteration 2 etc. </p>
  
  <p>I accomplished this by changing the code to this: </p>
  
  <pre><code> include &lt;stdio.h&gt;
  
  int iprint();
  int i=0;
  
  int main()
  {
    int j;
  
    for (j=0; j&lt;50; j++)
      {
        i= iprint(i);
        printf("%d\n",i);
      }
  }
  
  int iprint(i)
  {
    i +=1;
    //printf("%d\n",i); 
    return(i);
  }
  </code></pre>
  
  <p>Do i have to return(i) to make that happen? The reason for asking, is that if i have a lot of functions using i, it's a bit annoying having to pass i between them. If you instead, somehow could update i like you update a global variable in matlab, that'd be great. Is it possible?</p>