How to represent the Boolean "true" and "false" in C++

1 Answer

0 votes
// In C++, Boolean values are represented using the built‑in literals:
// true
// false

// '\0' -> false

// The Boolean type is bool, and printing them with 
// std::cout automatically shows "true" or "false" as text.

#include <iostream>

int main() {
    bool isActive = true;    
    bool isFinished = false;  

    std::cout << "isActive = " << isActive << std::endl;
    std::cout << "isFinished = " << isFinished << std::endl;

    // Boolean expression example
    bool result = (10 > 3);
    std::cout << "10 > 3 evaluates to: " << result << std::endl;
}


/*
run:

isActive = 1
isFinished = 0
10 > 3 evaluates to: 1

*/

 



answered Apr 14 by avibootz
edited Apr 14 by avibootz
...