title: (int*) when dynamically allocating array of ints in c
body: <p>So I'm a bit confused on how to make a <em>function that will return a pointer to an array of ints in C</em>. I understand that you cannot do:</p>
  
  <pre><code>int* myFunction() {
    int myInt[aDefinedSize];
    return myInt; }
  </code></pre>
  
  <p>because this is returning a pointer to a local variable.
  So, I thought about this:</p>
  
  <pre><code>int* myFunction(){
    int* myInt = (int) malloc(aDefinedSize * sizeof(int));
    return myInt; }
  </code></pre>
  
  <p>This gives the error: warning cast from pointer to integer of different size
  This implies to use this, which works:</p>
  
  <pre><code>int* myFunction(){
    int* myInt = (int*) malloc(aDefinedSize * sizeof(int));
    return myInt; }
  </code></pre>
  
  <p>What I'm confused by though is this:
  the (int*) before the malloc was explained to me to do this: it tells the compiler what the datatype of the memory being allocated is. This is then used when, for example, you are stepping through the array and the compiler needs to know how many bytes to increment by. 
  So, if this explanation I was given is correct, isn't memory being allocated for aDefinedSize number of pointers to ints, not actually ints? Thus, isnt myInt a pointer to an array of pointers to ints?
  Some help in understanding this would be wonderful. Thanks!!</p>