Monday, June 1, 2009

Bool Variables in C++

Ive been trying to work on C++ again....after 2 long years.... ive never

tried hard to understand this programming language....just studied C++ from

academic point of view.

Bool in C++ takes only 1 or 0 as inputs....i mean it expresses true or false

in terms of 1 and 0 respectively.

THe following code works in DEV C++ which uses gc++ compiler:

#include
int main()
{
bool real;
cout<
if(real==0)
cout<
real=2;
cout<
real="k";
cout<
real=0x22;
cout<
real=0;
cout<
real=-1;
cout<
real=-2222;
cout<
return 0;
}

irrespetive of assignment of values to a bool variable it is reflected as

true or 1; unless 0 is assigned or a bool variable is declared it has "0" by

default.