title: Changing type of variable during dynamic array passing to a function
body: <p>Guys my question is very simple but I am confused about the theory behind it. It would be lovely if someone can clarify.</p>
  
  <p>I want to pass a dynamic array of a certain type of variable and have a function convert that type of variable to another one and do more work on it before returning it in the form of a variable array of that new variable.</p>
  
  <p>Here's my not so functional code to show you what I was doing</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  //takes in unsigned char array, and returns unsigned short array
  
  unsigned short foo( unsigned char *array, int size) 
  {
      int i;
      unsigned short *LeArray = NULL;
      LeArray = (unsigned short*) malloc(size*sizeof(unsigned short));
      for ( i = 0; i &lt; size; ++i ) &amp;LeArray[i] = (unsigned char)&amp;array[i];
      //do more stuff to that array here before returning it
      return *LeArray;
  
  }
  int main()
  {
  
      int i, ArraySize;
      unsigned char *before = NULL;
      unsigned short *after = NULL;
      ArraySize = 9;
      before = (unsigned char*) malloc(ArraySize*sizeof(unsigned char));
      for(i = 0; i&lt;ArraySize; i++) before[i] = i+5; //to get some values in
      for (i = 0 ; i&lt;ArraySize; i++) printf("\npre:%d\n",before[i]);
      after = foo( before, ArraySize ); 
      for (i = 0 ; i&lt;ArraySize; i++) printf("\npost:%d\n",after[i]);
      return 0;
  
  }
  </code></pre>
  
  <p>Any help tips hints or explanations would be of great help to me!! Thanks so much!!</p>