Presumably your code
int length = 5;
int hi[length];
is at local scope, not file scope, as the latter wouldn't be legal.
Are they still going in the data-segment
They were never going in the data-segment; they go on the stack (in typical/common implementations; the language standard doesn't say where they go).
why would I still have to call delete[] on the 2nd example, but not
the 1st example?
First, VLA's (variable length arrays like hi[length]
) aren't legal in C++, so you couldn't call delete[]. But there's no need to call delete because hi
goes out of scope at the end of the block it's in. An object or array allocated by new
, OTOH, does not go out of scope until deleted. Only the pointer, hi
, goes out of scope, but you may have assigned its value to another pointer that is still in scope.