title: Memory allocation and changing values
body: <p>I am very new to C so sorry in advance if this is really basic.  This is related to homework.</p>
  
  <p>I have several helper functions, and each changes the value of a given variable (binary operations mostly), i.e.:</p>
  
  <pre><code>void helper1(unsigned short *x, arg1, arg2) --&gt; x = &amp;some_new_x
  </code></pre>
  
  <p>The main function calls other arguments <em>arg3, arg4, arg5</em>.  The <em>x</em> is supposed to start at 0 (16-bit 0) at first, then be modified by helper functions, and after all the modifications, should be eventually returned by <em>mainFunction</em>.</p>
  
  <p>Where do I declare the initial <em>x</em> and how/where do I allocate/free memory?  If I declare it within <em>mainFunc</em>, it will reset to 0 every time helpers are called.  If I free and reallocate memory inside helper functions, I get the "pointer being freed was not allocated" error even though I freed and allocated everything, or so I thought.  A global variable doesn't do, either.  </p>
  
  <p>I would say that I don't really fully understand memory allocation, so I assume that my problem is with this, but it's entirely possible I just don't understand how to change variable values in C on a more basic level...</p>