title: I want to add multiple values at the end of the array? I am not getting right answer with below code?
body: <p>Why I am getting wrong output?
  Suppose, If I am initializing 10 as array initial size and then 15 more elements to append at the end of an array. Then array total size will be 25. But in below code when I input multiple values to append at the end of array then after some input values either program stop or give wrong output.</p>
  <p><strong>Help Please !! Is Something wrong with my code?</strong></p>
  <pre><code>#include &lt;bits/stdc++.h&gt;
  using namespace std;
  
  int main()
  {
    int n,elem,lastindex=0;
    cin&gt;&gt;n;
    int arr[n];
    for(int i=0; i&lt;n; i++)
    {
      cout&lt;&lt;&quot;enter index &quot;&lt;&lt;i&lt;&lt;&quot; value number is &quot;&lt;&lt;i+1&lt;&lt;&quot;: &quot;;
      cin&gt;&gt;arr[i];
      lastindex++;
    }
    cout&lt;&lt;&quot;lastindex current value: &quot;&lt;&lt;lastindex&lt;&lt;endl;
    cout&lt;&lt;&quot;How many elements you want to add at the end of the element: &quot;;
    cin&gt;&gt;elem;
    elem = lastindex + elem;
    cout&lt;&lt;&quot;elem now: &quot;&lt;&lt;elem&lt;&lt;endl;
    for(int i=lastindex; i&lt;elem; i++)
    {
      cout&lt;&lt;&quot;enter index &quot;&lt;&lt;lastindex&lt;&lt;&quot; value number is &quot;&lt;&lt;lastindex+1&lt;&lt;&quot;: &quot;;
      cin&gt;&gt;arr[i];
      arr[lastindex] = arr[i];
      lastindex++;
      cout&lt;&lt;&quot;i: &quot;&lt;&lt;i&lt;&lt;endl;
      cout&lt;&lt;&quot;lastindex: &quot;&lt;&lt;lastindex&lt;&lt;endl;
      cout&lt;&lt;&quot;elem: &quot;&lt;&lt;elem&lt;&lt;endl&lt;&lt;endl;
    }
    cout&lt;&lt;&quot;last index current value: &quot;&lt;&lt;lastindex&lt;&lt;endl;
  //  arr[lastindex] = elem;
    for(int i=0; i&lt;lastindex; i++){
      cout&lt;&lt;arr[i]&lt;&lt;&quot; &quot;;
    }
  }
  
  
  
  </code></pre>