Share via


C6001

Note

This article applies to Visual Studio 2015. If you're looking for the latest Visual Studio documentation, see Visual Studio documentation. We recommend upgrading to the latest version of Visual Studio. Download it here

warning C6001: using uninitialized memory <variable>

This warning is reported when an uninitialized local variable is used before it is assigned a value. This could lead to unpredictable results. You should always initialize variables before use.

Example

The following code generates this warning because variable i is only initialized if b is true; otherwise an uninitialized i is returned:

int f( bool b )  
{  
   int i;  
   if ( b )  
   {  
      i = 0;  
   }  
   return i; // i is uninitialized if b is false  
}  

To correct this warning, initialize the variable as shown in the following code:

int f( bool b )  
{  
   int i= -1;  
  
   if ( b )  
   {  
      i = 0;  
   }  
   return i;  
}  

See Also

Compiler Warning (level 1 and level 4) C4700