Is ‘bool’ a basic datatype in C++? Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Is ‘bool’ a basic datatype in C++? without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I got this doubt while writing some code. Is ‘bool’ a basic datatype defined in the C++ standard or is it some sort of extension provided by the compiler ? I got this doubt because Win32 has ‘BOOL’ which is nothing but a typedef of long. Also what happens if I do something like this:

int i = true;

Is it “always” guaranteed that variable i will have value 1 or is it again depends on the compiler I am using ? Further for some Win32 APIs which accept BOOL as the parameter what happens if I pass bool variable?


bool is a fundamental datatype in C++. Converting true to an integer type will yield 1, and converting false will yield 0 (4.5/4 and 4.7/4). In C, until C99, there was no bool datatype, and people did stuff like

enum bool {
    false, true

So did the Windows API. Starting with C99, we have _Bool as a basic data type. Including stdbool.h will typedef #define that to bool and provide the constants true and false. They didn’t make bool a basic data-type (and thus a keyword) because of compatibility issues with existing code.

We are here to answer your question about Is ‘bool’ a basic datatype in C++? - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji