Compiler Error C2181

 

The new home for Visual Studio documentation is Visual Studio 2017 Documentation on docs.microsoft.com.

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

illegal else without matching if

Each else must have a matching if.

The following sample generates C2181:

// C2181.cpp  
int main() {  
   int i = 0;  
   else   // C2181  
      i = 1;  
}  

Possible resolution:

// C2181b.cpp  
int main() {  
   int i = 0;  
   if(i)  
      i = 0;  
   else  
      i = 1;  
}  

Show: