Skip to main content
Engineering LibreTexts

6.3: Boolean Data Type

  • Page ID
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)

    \( \newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\)

    ( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\id}{\mathrm{id}}\)

    \( \newcommand{\Span}{\mathrm{span}}\)

    \( \newcommand{\kernel}{\mathrm{null}\,}\)

    \( \newcommand{\range}{\mathrm{range}\,}\)

    \( \newcommand{\RealPart}{\mathrm{Re}}\)

    \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\)

    \( \newcommand{\Argument}{\mathrm{Arg}}\)

    \( \newcommand{\norm}[1]{\| #1 \|}\)

    \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\)

    \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    \( \newcommand{\vectorA}[1]{\vec{#1}}      % arrow\)

    \( \newcommand{\vectorAt}[1]{\vec{\text{#1}}}      % arrow\)

    \( \newcommand{\vectorB}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vectorC}[1]{\textbf{#1}} \)

    \( \newcommand{\vectorD}[1]{\overrightarrow{#1}} \)

    \( \newcommand{\vectorDt}[1]{\overrightarrow{\text{#1}}} \)

    \( \newcommand{\vectE}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash{\mathbf {#1}}}} \)

    \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \)

    \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)


    The Boolean data type is also known as the logical data type and represents the concepts of true and false. The name "Boolean" comes from the mathematician George Boole; who in 1854 published: An Investigation of the Laws of Thought. Boolean algebra is the area of mathematics that deals with the logical representation of true and false using the numbers 0 and 1. The importance of the Boolean data type within programming is that it is used to control programming structures (if then else, while loops, etc.) that allow us to implement "choice" into our algorithms.

    The Boolean data type has the same attributes and acts or behaves similarly in all programming languages. The rules within the C++ programming language are:

    C++ Reserved Word bool
    Represent Logical concepts of true and false
    Size Usually 1 byte
    Normal Signage Unsigned
    Domain (values allowed) 0 meaning false, and 1 meaning true
    C++ syntax rule true and false are reserved words that can be used as values in expressions
    C++ concept/rule Any value from any data type can be demoted into a Boolean data type with zero representing false and all non-zero values representing true

    Bool data type in C++

    The C++ Standard has added the bool data types to the C++ specifications.They are provided to provide better control in certain situations as well as for providing conveniences to C++ programmers.

    As mentioned above, bool values actually evaluate to either 0, which is FALSE, or 1, which is TRUE.

    bool b1 = true;      // declaring a boolean variable with true value   

    In C++, the data type bool has been introduced to hold a boolean value, true or false.The values true or false have been added as keywords in the C++ language.
    Important Points:

    • The default numeric value of true is 1 and false is 0.
    • We can use bool type variables or values true and false in mathematical expressions also.For instance,
      int x = false + true + 6;

      is valid and the expression on right will evaluate to 7 as false has value 0 and true will have value 1.

    • It is also possible to convert implicitly the data type integers or floating point values to bool type
      bool x = 0; // false 
      bool y = 100; // true 
      bool z = 15.75; // true


    Adapted from: 
    "Boolean Data Type" by Kenneth Busbee, Download for free at is licensed under CC BY 4.0
    "Bool data type in C++" by Mrigendra Singh, Geeks for Geeks is licensed under CC BY-SA 4.0 

    This page titled 6.3: Boolean Data Type is shared under a CC BY-SA license and was authored, remixed, and/or curated by Patrick McClanahan.