1

Receiving errors "C2057: expected constant expression" and "C2466: cannot allocate an array of constant size 0" on the second line when compiling.

I've looked into the error and the internet tells me that this usually happens because the compiler doesnt know how big the array needs to be but in this case I've told it in the line before.

const unsigned int N = 190788;

node* table[N];
  • 2
    Can't do that in C. Use `#define N 190788` instead. – goodvibration Aug 31 '20 at 15:21
  • Searching for any of “expected constant expression,” “C2057,” or “C2466” turns up duplicates. Some are shown by Stack Overflow when entering the text in this question. Please check for duplicates before entering questions. – Eric Postpischil Aug 31 '20 at 15:27
  • A `const`-qualified variable is not a *constant expression* in C; that is, something whose value is known at compile time. Since VS doesn't support variable-length arrays, array size expressions must be known at compile time. The problem is that `N` doesn't exist (and doesn't have a value) until *runtime*. You'll have to define `N` as a preprocessor macro like `#define N 190788` *or* use a C compiler that supports variable-length arrays (such as MinGW). – John Bode Aug 31 '20 at 15:28

0 Answers0