title: Invalid Pointer?
body: <p>I recently learned about pointers, and have been working hard to really understand them. However, I have run into trouble. For class we had to write a function that would double an array x amount of times. I was able to write the function without any real problems, but I'm trying to implement it into an actual code and I continue to get invalid pointer errors. Here's the code:</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  int *ArrayDoubling(int inputArray[], int initialSize, int numberToDouble);
  
  int main(){
      int arr[2] = {0,1};
      int array_size = 2;
      int number = 3;
  
      ArrayDoubling(arr, array_size, number);
  }
  
  int *ArrayDoubling(int inputArray[], int initialSize, int numberToDouble){
      for(int i=0;i&lt;numberToDouble;i++){
          int *array2 = new int[initialSize*2];
          for(int i=0;i&lt;initialSize;i++){
              array2[i] = inputArray[i];
          array2[i+initialSize] = inputArray[i]*2;
          }
          initialSize = initialSize*2;
          delete []inputArray;
          inputArray = array2;
      }
      return inputArray;
  }
  </code></pre>
  
  <p>So what exactly is causing the problem, and how can I fix it? Also not sure if this will actually print the output of the Array, but I'm also trying to get that to happen. Thanks for any and all help!</p>