In C ++ bool, it is a built-in type. Conversions of any type in boolalways give false(0) or true(1).
Prior to the 1999 ISO ISO standard, C had no built-in Boolean type. It was (and still is) for programmers to propagate their own Boolean types, for example:
typedef int BOOL;
#define FALSE 0
#define TRUE 1
or
typedef enum { false, true } bool;
1 , 0 1, 0 1 .
C99 _Bool, , , bool ++; bool, #include <stdbool.h>.
C ++ , undefined, , 0 1, bool. , :
bool b;
*(char*)&b = 2;
() 2 b, ++ , 0 1; , b == 0 b == true, .
:
- ,
bool. bool 0, 1, false true.
:
bool f() { return 42; }
, ++, C <stdbool.h>, true , , 1, 42 bool 1.
if (f() == 1)
printf("hello");
- bool, "hello".
. f() bool, . (, , ) :
if (f())
printf("hello");
f() == 1 , (f() == 1) == 1).
, -, , , :
if (greeting_required())
printf("hello");