Difficulty: Medium
Correct Answer: Error: unknown max in declaration/Constant expression required
Explanation:
Introduction / Context:
This question contrasts classic Turbo C behavior with modern C99+. In Turbo C (pre-C99), array bounds must be compile-time integer constant expressions (ICEs). A const int variable is not an ICE for that compiler.
Given Data / Assumptions:
Concept / Approach:
In old compilers without variable length arrays (VLAs), array sizes must be literal constants, enum constants, or macro constants. Using const int max as an array bound triggers an error similar to “constant expression required.”
Step-by-Step Solution:
Define const int max = 128; → not an ICE in Turbo C.Declare char array[max]; → Turbo C errors: constant expression required.Declare char string[MAX]; → OK because MAX is a macro constant.Hence the program fails to compile due to array[max].
Verification / Alternative check:
On a modern C99+ compiler with VLAs, char array[max]; would compile. Specifying -std=c89 or using Turbo C reproduces the error.
Why Other Options Are Wrong:
“invalid array string” misidentifies the line. “No error” is false for Turbo C. “None of above” is unnecessary because (a) states the correct diagnostic.
Common Pitfalls:
Assuming const int is always a compile-time constant; confusing language standards and compiler capabilities; forgetting that VLAs appeared only in C99.
Final Answer:
Error: unknown max in declaration/Constant expression required
Discussion & Comments