The Nature of Truth

In previous versions of C++ all truth and falsity were represented by integers, but the new ISO/ANSI standard has introduced a new type: bool. This new type has two possible values, false or true.

Every expression can be evaluated for its truth or falsity. Expressions that evaluate mathematically to zero will return false, all others will return true.

Many compilers previously offered a bool type that was represented internally as a long int and thus had a size of 4 bytes. ANSI compliant compilers will now often provide a 1-byte bool.

Get Sams Teach Yourself C++ in 24 Hours, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.