C/C++ C++: What is Boolean Data Type & What Does it Do?

  • Thread starter Thread starter ineedhelpnow
  • Start date Start date
  • Tags Tags
    C++ Data
AI Thread Summary
Boolean values represent two states: true or false, and the bool data type in programming is used to handle these values. In the provided code snippet, bool variables like isLarge and isNeg are initialized to false, which can serve various purposes in a program. A common use of bool is as a flag in control structures, such as loops, to determine when to exit. Essentially, any condition that can be evaluated as true or false is suitable for using the bool data type, making it a fundamental component in programming logic and decision-making.
ineedhelpnow
Messages
649
Reaction score
0
Boolean refers to a quantity that has only two possible values, true or false.

The language has the built-in data type bool for representing Boolean quantities.

thats what my book says. i don't really understand the purpose. here's a passage from my book:
Code:
int main() {
   bool isLarge = false;
   bool isNeg   = false;
   int  userNum = 0;

what is bool for? what does it do?
 
Last edited:
Technology news on Phys.org
One example would be as use for a flag that indicates when a looping construct should quit. Really though, any condition in your program that will only be either true or false is a good candidate for this data type.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Back
Top