title: How to create a pointer to pointer array to struct?
body: <p>I want to create a dynamic array of pointers that each one of them points to a struct. In the program there is an option to add structs and if the counter reaches the last the value of the array, the array expands.</p>
  
  <pre><code>struct student
  {
      string id;
      string name;
  };
  
  int N=5;
  int counter=0;
  student **big=new student *[N]; //a ptr to an array of ptr's.
  
  void add_student (int &amp;counter,student **big)
  {
      int i;
  
      if (counter==0)
      {
          for (i=0; i&lt;N; i++)
          {
              big[i]=new student; 
          }
      }
  
      if (counter==N)
      {
          N+=5;
          student **temp=new student *[N];
          for (i=counter-1; i&lt;N; i++)
          {
              temp[i]=new student;
          }
  
          for (i=0; i&lt;counter; i++)
          {
              temp[i]=big[i];
          }
  
          delete [] big;
          big=temp;
      }
  
      cout&lt;&lt;"Enter student ID: "&lt;&lt;endl;
      cin&gt;&gt;(*big)[counter].id;
  
      cout&lt;&lt;"Enter student name: "&lt;&lt;endl;
      cin&gt;&gt;(*big)[counter].name;
  
      counter++;
  }
  </code></pre>
  
  <p>When I run the program it crashes after I try to add more than one student. Thanks!</p>