Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » C++
Language: C++
Expertise: Advanced
Mar 2, 1998

Advantages of bool type

Standard C++ supports a built-in Boolean type: Bool. Variables of this type are can be assigned either a true or false values exclusively ( true and false are now reserved keywords in the laguage) and are at least as efficient as any other primitive type such as char or int. What are the advantages of using a bool instead of plain int? *Portability. All Standard conforming compilers support bool type. Should your code be ported, it is guaranteed that it will work as expected in other environments as well. *Readability. Needless to say, using explicit terms such as true, false and bool are much more self-documenting than the following deprecated example. In fact, such code samples are not guaranteed to work in future versions of C++ so they are better avoided:
 //better avoid this

	int done = 0; //very bad; readers should guess 0 means 
Danny Kalev
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date