Boolean types

A Boolean variable can be used to hold the integer values 0 or 1, or the literals true or false, which are implicitly promoted to the integers 0 and 1 whenever an arithmetic value is necessary. The Boolean type is unsigned and has the lowest ranking in its category of standard unsigned integer types; it may not be further qualified by the specifiers signed, unsigned, short, or long. In simple assignments, if the left operand is a Boolean type, then the right operand must be either an arithmetic type or a pointer.

C only

Boolean types are a C99 feature. To declare a Boolean variable, use the _Bool type specifier. IBM extensionThe token bool is recognized as a keyword in C only when used in a vector declaration context and VMX support is enabled.

End of C only
C++ only

To declare a Boolean variable in C++, use the bool type specifier. The result of the equality, relational, and logical operators is of type bool: either of the Boolean constants true or false.

End of C++ only

You can use Boolean types make Boolean logic tests. A Boolean logic test is used to express the results of a logical operation. For example:

_Bool f(int a, int b)
  return a==b;

If a and b have the same value, f returns true. If not, f returns false.

Related information