I know that in C++ you cannot declare the size the array with a run-time variable, but I am interested in making sure whether the following would be legal:
#include directives
const int SIZE=5;
double a[SIZE];
Thank you!!
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.
Yes it is legal in C++ and C both.
SIZEneeds to be a constant expression and in C++const int SIZE=5;declares it so.In C prior to introduction of variable length arrays in C99,
would yield a error because in this case
SIZEis not a constant expression but merely readonly and it needs to be a constant expression to be valid.