Alex Rivera | Logout

Default constructor value for bool type

Asked 2010-07-22T10:52:06.100
22

Which value does the default constructor of the bool type return in C++?

For instance, writing

int i = int();

guarantees that the variable i will be initiated always with 0.

I guess such an initialization routine is possible as well:

bool b = bool();

But unfortunately I could not find anywhere which value such a default bool constructor is defined to return. Is the variable b always initialized with false or true.

Edit
Report

1 Answer

1

bool behaves 'as if it were declared':

enum bool {false,true};

It is an integral type and might be casted to int as values 0 and 1 (respectively), and its default value is false.

answered 2010-07-22T14:55:04.877

Your Answer