New Fundamanental Type

New Fundamanental Type - New Fundamanental Type - bool A...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
New Fundamanental Type - bool A new fundamental (builtin) type has recently been added to C++. It is a type for representing Boolean values and uses the keyword "bool". For example, you could say: bool b; b = true; if (b) ... A bool value is either true or false. A bool value can be converted to an integer: bool b; int i; b = false; i = int(b); in which case false turns into 0 and true into 1. This process goes under the C/C++ name of "integral promotion". A pointer, integer, or enumeration can be converted to a bool. A null pointer or zero value becomes false, while any other value becomes true. Such conversion is required for conditional statements: char* p; ... if (p) ... In this example "p" is converted to bool and then the true/false value is checked to determine whether to execute the conditional block of code. Why is a bool type an advantage? You can get a variety of opinions on whether this is a step forward. In C, common usage to mimic this type would be as follows: typedef int Bool;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 3

New Fundamanental Type - New Fundamanental Type - bool A...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online