title: C++ Pointer of Array of Ints Initialization
body: <p>I want to have an array accessible by all functions of a class. </p>
  
  <p>I put the array as private variable in the header file. </p>
  
  <pre><code>    private:
      int* arrayName;
  </code></pre>
  
  <p>In the .cpp file where I implement the class, the constructor takes in an int value (size) and creates the array. The goal is to fill it up</p>
  
  <pre><code>ClassName::ClassName(int numElements){
    arrayName = new int[numElements]; //make arrays the size of numElements
    for(int i = 0; i&lt;numElements; i++)
        arrayName[i] = 0;
  }
  </code></pre>
  
  <p>I feel like this is quite inefficient. I know you can do int array[5] = {0}; but how do you do it when you don't initially know the size. </p>