Q58 What is constant expression required error in array?

Is below statement is correct?

int value = 20;

int arr[value];

Compiler will through error like Constant expression required while compiling above line.

Array size should always be mentioned with a positive integer because size cannot be in negative value. Declaring like  arr[20] is correct but arr[value] is invalid declaration even value has been declared before array declaration.

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.