filipanton1
filipanton1

Reputation: 67

The size of an array

Is it true that the size of an array has to be a constant variable? Like for example,

const int size = 5;//would int size = 5 not be allowed?
int array[size];

Also if this this is true what happens when you work with dynamic arrays? Would int size = 5; be fine then?

Upvotes: 0

Views: 75

Answers (1)

Matthieu Brucher
Matthieu Brucher

Reputation: 22043

In C++, yes, arrays have to have a compile time value (explicit content or a constant variable).

Variable Length Arrays are C99, and a GCC extension. You should not use them in C++, even if g++ allows them.

Upvotes: 2

Related Questions