TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Tuesday 26 May 2020

Bool Data Type In C++ | Bool Data Type In C++ Programming Language

Bool data type in C++


The ISO/ANSI C++ Standard has added certain new data types to the original C++ specifications.They are provided to provide better control in certain situations as well as for providing conveniences to C++ programmers.

One of the new data type is: bool

image of Bool Data Type In C++

Fig: Bool Data Type In C++ 


Syntax:

bool b1=true   //declaration  a boolean  with a true value

The data type bool has been introduced to hold a boolean value, true or false.The values true or false have been added as keywords in the C++ language.


Important Points:

 

·         The default numeric value of true is 1 and false is 0.

 

·         We can use bool type variables or values true and false in mathematical expressions also.

 

·         It is also possible to convert implicitly the data type integers or floating point values to bool type.


 

Program:

 

#include<iostream>

using namespace std;

int main()

{

       int x1 = 10, x2 = 20, m = 2;

       bool b1, b2;

       b1 = x1 == x2; // false

      

       b2 = x1 < x2; // true

      

       cout << "b1 is = " << b1 << "\n";

       cout << "b2 is = " << b2 << "\n";

       bool b3 = true;

      

       if (b3)

                 cout << "Yes" << "\n";

       else

                 cout << "No" << "\n";

                

       int x3 = false + 5 * m - b3;

       cout << x3;

      

return 0;

      

}

 

 

Output:

 

b1=0

b2=1

yes

9

 


No comments:

Post a Comment