Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
C6001
Collapse the table of content
Expand the table of content

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;
}
Show:
© 2015 Microsoft