dynamic array without new operator?

arrays, c++, memory-management

Solution

Varialbe length arrays (VLAs) are not standard C++, they are a compiler extension. You shouldn't use it if you want your code to be portable.

If you compile with the `-Wvla -Werror` flags, or `-Werror=vla`, your code will produce the error

error: variable length array 'dynamic_arr' is used [-Werror=vla]

Problem

Since when is this valid syntax? (works using g++ 4.6.3) What should I search on to find further information about this (I'm used to new/delete)? ``` #include <iostream> int main(){ size_t sz; std::cout<<"number?\n"; std::cin>>sz; // This line float dynamic_arr[sz]; //output the (uninitialized) value just to use the array. std::cout<<dynamic_arr[0]<<std::endl; return 0; } ```

Original source

Related problems