Expand Minimize

C6001

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.

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 unintialized 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;
}
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft