While studying pointer in C++, I encountered "Dynamic Memory allocation in arrays" which we execute like this :
int *array_ptr {std::nullptr};
size_t size{};
cout<<"Enter the size of the array: "<<endl;
cin>>size;
array_ptr = new int [size];
But my question is we can simply accomplish this by another method which is :
size_t size{};
cout<<"Enter the size of the array: "<<endl;
cin>>size;
int array [size] {};
The second method will do the same job as the first one. Then why do we use the first method in the first place? Is it just to save the memory?