79.9k views
2 votes
An array's size declarator must be a ________ with a value greater than ________.

User Skqr
by
9.0k points

1 Answer

4 votes
(note that examples are in C++)


Firstly, it must be a constant. Because you can't do something like this:

int x = 5;
int arr[x];

Because x's value could change over time, which is why you get a compile error. If x was a constant, indicated by keyword 'const', then this would compile, as x's value could never change.


Secondly, and obviously, the size of the array must be greater than 0, as you can't have an array with zero or negative number of elements.
User Hyarion
by
8.2k points