#include <iostream>
#include <cstring>

int main() {
    
    // std::cout << true  << std::endl;  // 0
    // std::cout << false << std::endl;  // 1
    // std::cout << std::boolalpha;
    // std::cout << true  << std::endl;  // true
    // std::cout << false << std::endl;  // false
    
    // bool a = true;
    
    // int b = a;
    // std::cout << a << std::endl;  // 1
    // std::cout << b << std::endl;  // 1
    
    // int c = -999;
    // bool d = c;
    // int e = d;
    // std::cout << c << std::endl;  // -999
    // std::cout << d << std::endl;  // 1
    // std::cout << e << std::endl;  // 1
    
    // std::cout << sizeof(bool);  // 1
    
    // GOOD
    // bool arr[8] = { false };
    // for (int i = 0; i < 8; i++){
    //     std::cout << arr[i] << std::endl;
    // }
    
    // BAD only sets first value
    // bool arr[8] = { true };
    // for (int i = 0; i < 8; i++){
    //     std::cout << arr[i] << std::endl;
    // }
    
    // OK
    // bool arr[8];
    // memset(arr, false, 8*sizeof(bool));
    // for (int i = 0; i < 8; i++){
    //     std::cout << arr[i] << std::endl;
    // }
    
    // Definitely OK here since bool is 1 byte.
    // Maybe also ok if bool were multiple bytes since my casting
    // experiments above show any non-zero int getting converted to 1?
    // bool arr[8];
    // memset(arr, true, 8*sizeof(bool));
    // for (int i = 0; i < 8; i++){
    //     std::cout << arr[i] << std::endl;
    // }
    
    // prints 8 5s
    // bool arr[8];
    // memset(arr, 5, 8*sizeof(bool));
    // for (int i = 0; i < 8; i++){
    //     if (arr[i]) {
    //         std::cout << arr[i] << std::endl;
    //     }
    // }  
    
    // prints 8 trues
    // std::cout << std::boolalpha;
    // bool arr[8];
    // memset(arr, 5, 8*sizeof(bool));
    // for (int i = 0; i < 8; i++){
    //     if (arr[i]) {
    //         std::cout << arr[i] << std::endl;
    //     }
    // }  
    
    // bool arr[8];
    // memset(arr, 5, 8*sizeof(bool));
    // // 5 for each
    // std::cout << arr[0] << std::endl;  
    // std::cout << (arr[0] == true) << std::endl;  
    // std::cout << (arr[0] != false) << std::endl;  
    // std::cout << (!!arr[0]) << std::endl;  
    // std::cout << ((!!arr[0]) == true) << std::endl;
    // // true for each
    // std::cout << std::boolalpha;
    // std::cout << arr[0] << std::endl;  
    // std::cout << (arr[0] == true) << std::endl;  
    // std::cout << (arr[0] != false) << std::endl;  
    // std::cout << (!!arr[0]) << std::endl;  
    // std::cout << ((!!arr[0]) == true) << std::endl;
    
    // bool arr[8];
    // memset(arr, 5, 8*sizeof(bool));
    // if (arr[0]) { std::cout << 1 << std::endl; }              // prints
    // if (arr[0] == true) { std::cout << 2 << std::endl; }      // does not
    // if (arr[0] != false) { std::cout << 3 << std::endl; }     // prints
    // if (!!arr[0]) { std::cout << 4 << std::endl; }            // prints
    // if ((!!arr[0]) == true) { std::cout << 5 << std::endl; }  // does not
    
    // bool arr[8];
    // memset(arr, true, 8*sizeof(bool));
    // if (arr[0]) { std::cout << 1 << std::endl; }              // prints
    // if (arr[0] == true) { std::cout << 2 << std::endl; }      // prints
    // if (arr[0] != false) { std::cout << 3 << std::endl; }     // prints
    // if (!!arr[0]) { std::cout << 4 << std::endl; }            // prints
    // if ((!!arr[0]) == true) { std::cout << 5 << std::endl; }  // prints
        
    // bool arr[8];
    // memset(arr, -1, 8*sizeof(bool));
    // if (arr[0]) { std::cout << 1 << std::endl; }              // prints
    // if (arr[0] == true) { std::cout << 2 << std::endl; }      // does not
    // if (arr[0] != false) { std::cout << 3 << std::endl; }     // prints
    // if (!!arr[0]) { std::cout << 4 << std::endl; }            // prints
    // if ((!!arr[0]) == true) { std::cout << 5 << std::endl; }  // does not
    
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: