title: Setting and getting values of array from typedef struct in C
body: <p><strong>The definition of intarr_t:</strong></p>
  
  <pre><code>typedef struct {
      int* data;
      unsigned int len;
  } intarr_t;
  </code></pre>
  
  <p>First, I need to set a value to a given index of array and return typedef'd status codes accordingly.</p>
  
  <p><strong>My work for setting a value to an array is:</strong></p>
  
  <pre><code>intarr_result_t intarr_set( intarr_t* ia, 
                  unsigned int index, 
                  int val )
  {
      if(ia == NULL)  // if ia is null
      {
          return INTARR_BADARRAY;
      }
  
      unsigned int len = ia-&gt;len;
  
      if(index &gt;= 0 &amp;&amp; index &lt; len)   // if index is valid
      {
          ia[index].data = &amp;val;  // set value at ia[index] to val
  
          return INTARR_OK;
      }
      else    // if index is not valid
      {
          return INTARR_BADINDEX;
      }
  }
  </code></pre>
  
  <p>Second, I need to set a value of an array to a pointer variable.</p>
  
  <p><strong>My work to get a value is:</strong></p>
  
  <pre><code>intarr_result_t intarr_get( const intarr_t* ia, 
                  unsigned int index, 
                  int* i )
  {
      if(ia == NULL)
      {
          return INTARR_BADARRAY;
      }
  
      unsigned int len = ia-&gt;len;
  
      if((index &gt;= 0 &amp;&amp; index &lt; len) &amp;&amp; i != NULL)
      {
          i = ia[index].data;
  
          return INTARR_OK;
      }
      else
      {
          return INTARR_BADINDEX;
      }
  }
  </code></pre>
  
  <p>When testing myself, I get a value from what I set, but the automated marker says the values returned, at the same index, from each functions is different to each other. I'm not sure where I did wrong and how I should fix it. Help me out please.</p>