Introduction to Boolean in C++ Programming Language

Boolean in C++ Programming Language





C++ Booleans regularly, in programming, you will require an data type that can have one of two values as:

  1. Yes / NO
  2. On / Off
  3. True / False

C++ Programming Language has a bool data type, which could take the values yes ( 1 ) or no ( 0 ).


Boolean Values:
A Boolean variable is declared with the bool keyword and can take the values true / false:

Example: Code in C++
#include <iostream>
using namespace std ;
int main( ) {
  bool yes = true;
  bool no = false;
  cout << yes << endl ;
  cout << no << endl ;
  return 0 ;
}

From the Example above, you can peruse that a true value returns 1, and false returns 0. Be that as it may, returning a Boolean value by looking at values and variables is more normal


Boolean Expression
A Boolean Expression returns a boolean value that is either 1 ( yes ) or 0 ( no ). This is valuable to build logic, and track down answers.
You can utilize a  comparison operator, for example, the larger than ( > and == ) operator, to see whether an expression (or variable) is true or false:

Example: Code in C++
#include <iostream>
using namespace std ;
int main( ) {
  int a = 20 ;
  int b = 10 ;
  cout << (a > b ) ;
  return 0 ;
}

Example: Code in C++
#include <iostream>
using namespace std ;
int main( ) {
  int a = 20;
  cout << ( a == 20 ) ;
  return 0 ;
}









I hope You can easily Understand and Learn this Article

Best of Luck 😇

Post a Comment

0 Comments