title: C++ malloc - dynamic array
body: <p>Assuming that I have a program that has an array of unknown lenght that consists of <code>Customer</code>s.</p>
  
  <p>Here, a customer struct:</p>
  
  <pre><code>struct Customer
  {
   char* lastname;
   char* firstname;
   int money;
  };
  </code></pre>
  
  <p>And here - an array:</p>
  
  <pre><code>Customer* CustomerDB;
  </code></pre>
  
  <p>Okay. But the thing is that I want to add and remove customers dynamically during runtime. I don't want to allocate like 100 customers during declaration or during runtime - I want to allocate one at a time when it is needed.</p>
  
  <p>Think of a simple AddCustomer function that allocates memory, enters the given data and then increments a counter (which is probably needed for iteration).</p>
  
  <p>This is my main problem.</p>
  
  <p>What I want is the array to behave exactly like one that has been declared with 100 arrays instead of a dynamical one.</p>
  
  <p>The customer program above is just an <em>example</em>, please don't tell me that it's a bad idea to do that and that or that.</p>
  
  <ul>
  <li><p>How do I create an <code>AddCustomer</code> function working for the code above?</p></li>
  <li><p>It is necessary that I can iterate through <code>CustomerDB</code></p></li>
  </ul>