wrote:
> Hi,
>
> I wonder if this is a legal array declaration?
>
> const int size = 5;
> double array[size];
>
> Or should I use "new"?
>
> Thanks.
You should use the constant expression for a statically-sized array
since the number of bytes needed is known at compile time. Using new in
this situation incurs unnecessary overhead at runtime; worse, it
imposes on the program a requirement to call delete on the array, which
if neglected, will cause memory to leak.
In general, use new to allocate arrays that are either too large to be
allocated on the stack or whose size is not known until runtime.
Greg