Double Dynamic Array?

I have declared a dynamic array. I filled the array with integer data.
Can I alter the size of the array after it has been declared and initialized?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
using namespace std;
int main()
{
    int size, x;
    
    cout<<"\nEnter array size: ";
    cin>>size;
    int array[size-1];
    for(x=0;x<=size-1;x++)
    {
    array[x]=x+1;
    cout<<"\nArray element "<<x<<" is equal to "<<array[x];
}
int size2;
    cout<<"\nHow much do you want to increase the array by?";
    cin>>size2;
    
    //what code do I use here increase the already created array???
}
  
Your code does not satisfies requirements of C++. In C++ array size shall be a constant expression. There are no variable length arrays in C++.
Last edited on
Topic archived. No new replies allowed.