Skip to main content
2 of 2
trim to minimal problem
UpAndAdam
  • 1.7k
  • 1
  • 3
  • 20

Are boolean variables left uninitialized true or false?

I have a question about why something is being done in the provided stub code for Tideman.

here bool locked[MAX][MAX] is left uninitialized early in the program when it is declared. Later every element of locked is assigned false in main using for loops.

I have learned the default value of booleans is false, so it seems to me locked doesn't need to be assigned false explicitly. Would you teach me for what purpose locked is assigned false in this program?

/// some code, it defines MAX 

// locked[i][j] means i is locked in over j
bool locked[MAX][MAX];

/// more code introduces `candidate_count`

int main(int argc, string argv[])
{
    /// some code here
    /// notably it assigns `candidate_count` to a value less than `MAX`

    // Clear graph of locked in pairs
    for (int i = 0; i < candidate_count; i++)
    {
        for (int j = 0; j < candidate_count; j++)
        {
            locked[i][j] = false;
        }
    }

    /// more code follows
}