why can we do this in c?
int n;
scanf("%d",&n);
int a[n];
I thought array is located memory during load time but seems like the above example works during runtime.
Do I misunderstand any thing? can you guys help?
Thanks,
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.
I thought array is *al*located memory during load time but seems like the above example works during run-time.Yes, ordinary arrays like
<datatype> <Array_Name> [<size>]is allocated memory during load time it is there in C89 and also existed in C99.But in the code snippet
int a[n];is a Variable Length Array or VLA for short.VLA’s in C99 are defined just like any other array, except that the length doesn’t need to be a compile-time constant.A decent article on the need of VLAs can be found here :http://www.ddj.com/cpp/184401444 🙂