I'm a beginner in C++. I had seen one sample code as shown below:
int quantity;
cout << "Enter the number of items: " << endl;
cin >> quantity;
int *arr = new int[quantity];
for(int i=0; i <quantity; i++)
{
cout<< "Enter item no." << i << endl;
cin >> arr[i];
}
But when I replaced the int *arr = new int[quantity];
with int arr[quantity];
, the program can still be compiled without any error messages. Why is int *arr = new int[quantity]
used instead of int arr[quantity]
?