0

Through dynamic memory allocation, the following the code works perfectly.

int *ptr;
int size1;

cin >> size1;

ptr = new int[size1];

In static memory allocation, I get the following error: array bound is not an integer constant before ']' token

int size2;
cin >> size2;
int arr[size2];

Why is this so? Why can't we specify a variable size?

Jarod42
  • 203,559
  • 14
  • 181
  • 302
Moiz Sajid
  • 644
  • 1
  • 10
  • 20

1 Answers1

1

Variable length array is an extension supported by certain compilers and it not (yet) in the standard.

Jarod42
  • 203,559
  • 14
  • 181
  • 302