Our professor taught us to use an indirection operator (*) when accessing a dynamic variable. Hence, I fail to understand why the code is written like this:
cout << arr[i];
And not like this:
cout << *arr[i];
Here is the entire code:
#include <iostream>
using namespace std;
int main()
{
int size;
int *arr;
cout << "Please enter size: ";
cin >> size;
arr = new int[size];
cout << "Enter " << size << " items" << endl;
for (int i = 0; i < 5; i++)
{
cin >> arr[i];
}
cout << "You entered: ";
for (int i = 0; i < 5; i++)
{
cout << arr[i] << " ";
}
}
delete[]at the end. If you dont want to write it, you can usestd::unique_ptr<T[]>