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;
}
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]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With