Compiler Error C2540


The new home for Visual Studio documentation is Visual Studio 2017 Documentation on

The latest version of this topic can be found at Compiler Error C2540.

non-constant expression as array bound

An array must have a constant bound.

The following sample generates C2540:

// C2540.cpp  
void func(int n, int pC[]) {  
   int i = ((int [n])pC)[1];   // C2540  
void func2(int n, int pC[]) {  
   int i = (pC)[1];   // OK  
int main() {  
   int pC[100];  
   func(100, pC);  
   func2(100, pC);