Visual Studio is giving error while compiling this c++ code. It says that size should be a constant variable. I have tried making it constant but it does not work.
int size;
cout << "Please Enter the array size : " ;
cin >> size;
int myArr[size];
Visual Studio is giving error while compiling this c++ code. It says that size should be a constant variable. I have tried making it constant but it does not work.
int size;
cout << "Please Enter the array size : " ;
cin >> size;
int myArr[size];
The size of an array must be known at compile time. In your case, the size is known at runtime so you must allocate the array from the heap.
int size;
std::cin >> size;
int* myArr = new int[size];
// ...
delete[] myArr;