Using memset on array of bool (C++)

Revision en1, by marlonbymendes, 2016-12-21 00:20:24

The following piece of code:

    const int N = 10;
    bool can[N];
    memset(can, -1, sizeof can);

    if(can[0] == 0) { // can[0] == false gives same result
        cout << "is zero";
    }
    else {
        cout << "not zero";
    }

Outputs is zero, however I expected it to be not zero.

Using memset like this instead:

    memset(can, 1, sizeof can); // using true instead of 1 gives same result

Outputs not zero as expected. What is going on?

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English marlonbymendes 2016-12-21 00:20:24 549 Initial revision (published)