bool type

I read some info about "bool" before and there I remember it was written bool type is implemented as int in some systems.Is it so? In my system I see sizeof bool as 1.
Anyway,I think I made the below stupid mistake by assuming it will hold a value greater than 1.

1
2
3
4
5
bool tog=0;
.....
....
//somewhere below
if(key_a_pressed) {tog++; tog%=2;}


This way it always holds value of "1".The assumption that it will be 2 and then 0 with % operation is not correct.

IIRC - the C++ bool type will only hold numerical values of 0 or 1 (false or true)

Some C sytems defined their own boolean type as C did not have an 'official' boolean type:

For example Window api BOOL is an integer (typedef int BOOL)
and so can be used to hold any value that an integer can hold - 0 being false and any other value
being true (but the values defined in the WinApi as FALSE and TRUE are 0 and 1).
Last edited on
Thanks for your comments.
Topic archived. No new replies allowed.