Dec 20, 2011

Program : Using Bool Data Type

Using Bool Data Type

Bool data type can store two value only 0 or 1. o for False & 1 For True. if define Bool variable and that variable contain value more than 1 it store only 1 like i declare bool variable az = 1212313; it store az = 1 or az = true; it store az =1 & it shows zero when its False or value is Zero only.


Let Check Out Example :-

#include<iostream.h>
#include<conio.h>
int main()
{
    //Using Bool Data Type
    bool a = 321, b; /*Declare two bool variable. Bool store two type of value true or falue and this show
     bu integer value 1 for true and 0 for false like here i initialize bool a
     with 321 value it store 1 in it let see*/
    cout << "Bool a Contains : " << a; // print a it show 1
    int c = true; // it store value 1 for true and 0 for false
    c = a + a; // a value is 1 and 1 add to 1 gives 2
    cout << "\nInteger c contain : " << c; //print c value
    b = c + a; 

/* it 2 + 1 it give 1 because its type is bool so it show only 0 and 1*/
    cout << "\nBool b contain : " <<b;
 
    getch();
    return 0;



Output




0 comments:

Post a Comment