Wednesday, 3 September 2014

Boolean in C++ vs java

In java boolean is a type and and it can take two values namely, true and false. "boolean" is also a keyword in java, and therefore cannot be used to name identifiers.

in C++ bool is the corresponding variable type with boolean in java. Same as java it can take two values namely true(which converts to an integral one) and false(which converts to an integral zero). The difference is in C++ both true and false are also keywords.

In C++ identifiers cannot be named as true or false because they are keywords in the language, but in java they are not keywords but literals , and still cannot be used as identifiers.