AFAIK this code is not a valid c++ code by standard:
int a = 5;
int b[a];
but it seems many compilers can compile that code (mostly with warning) and it just behaves as expected. Am I wrong is is it compilers being nice to me?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It is called variable length array (VLA) which is not allowed by Standard C++, any version of C++, though some GCC supports this as an extension.
If you’re using GCC, then
-pedanticoption, you will see warning.-pedantic -Werroroption, you will see warning turned into error.VLA is allowed only by C99, though not by other versions of C.