View Single Post
  #1 (permalink)  
Old May 4th, 2008, 06:06 AM
code_lover code_lover is offline
Authorized User
 
Join Date: Jan 2007
Posts: 46
Thanks: 2
Thanked 1 Time in 1 Post
Default The boolean data type in C++?


When i assign a non-zero value to a boolean variable, the output is true. And when i assign a non-zero value from the console, the output is false.
WHY?

Please take a look at the following codes:
#include <iostream.h>
#include <conio.h>

main()
{
bool bln;
cout<<"Enter value: ";
cin>>bln;

if (bln==true)
{
cout<<bln<<"TRUE";
}
else
{
cout<<bln<<"FALSE";
}
getch();
}

Output:
0FALSE


/*************************************...
#include <iostream.h>
#include <conio.h>

main()
{
bool bln=253;


if (bln==true)
{
cout<<bln<<"TRUE";
}
else
{
cout<<bln<<"FALSE";
}
getch();
}

Output:
1TRUE

MAXOOD!

Life is an endless journey towards perfection
__________________
MAXOOD!

Life is an endless journey towards perfection
Reply With Quote