#include <iostream>
usingnamespace std;
int main(void)
{
size_t number;
cout << "How many numbers would you like to type? ";
cin >> number;
int arr[number];
for (size_t n = 0; n != number; ++n) {
cout << "Enter number: ";
cin >> arr[n];
}
cout << "You have entered: ";
for (size_t n = 0; n != number; ++n)
cout << arr[n] << " ";
cout << endl;
return 0;
}
I suppose that line 12 will generate an error since for static allocation, only "fixed"-size array can be defined. However, the above code runs just as correctly as using new and delete.
GCC has an extension allowing variable sized runtime arrays, which technically aren't legal until C++14 is released. If you want to generate an error from this, as you should, when compiling specify -Wall -Wextra -pedantic-errors in your command line for building (In the build options if you are using code::blocks).