2

I've had an argument with a friend about declaring an array like this:

int n;
std::cin >> n;
int array[n];

I've learned that this is wrong since the number n is not a compile time constant. However my friend who is attending private lessons (free training for scool programming competitions) told me that that's what they taught them to do. By the way, I'm learning on my own from www.learncpp.com

Could you please tell me why he can do it since it's wrong ? Or am I wrong? I'm really confused about this since I've tried doing it they way I wrote above and the compiler didn't throw any errors.

alienCY
  • 225
  • 2
  • 12

0 Answers0