title: Avoiding Side Effects in C
body: <p>This question particularly applies to arrays.</p>
  <p>In many languages, I would do something like this:</p>
  <pre><code>    #This is in python for simplicity:
  
      def increment(mylist):
          for i in mylist:
              i += 1;
              
          return mylist
      
  
      mylist = {0,1,2,3}
      mylist = increment(mylist)
  </code></pre>
  <p>I tried several ways to return arrays in C, none of which worked as above. It seems that C simply was not intended to work this way. Instead, I had to do this:</p>
  <pre><code>#include &lt;stdio.h&gt;
  
  increment(int *myarray, int size) {
      for(int i = 0; i &lt; size; i++){
          myarray[i] += 1;
          
      }
  }
  
  int main(){
      int myarray[4] = {0,1,2,3};
      increment(myarray, 4);
  
  }
  </code></pre>
  <p>Needless to say, the C function changes the state of the array and is therefore a side effect function. There are good reasons to avoid this (which are not the topic of this question).</p>
  <p>Is there a way to avoid these types of side effects in C?</p>