Add Your Heading Text Here

Booleans are the data types which can have only 2 values true and false.

Now, you’ll think how a data type with only 2 values can be so useful in programming logic.

But, you will know that Booleans are so useful to test any conditional expression.

For ex :

do you want to go to School? //It can have only 2 values ‘Yes’ or ‘No’.

So, similarly Boolean data type uses true and false values which acts as the conditional results for different situations.

To declare any variable as Boolean, bool keyword is used.

For ex :

void main()
{
  bool value;
  print(value);
}

Default value for booleans is null.

You can directly provide the values to boolean variables like,

For ex :

void main()
{
  bool value=false;
  print(value);
}

Similarly we can use booleans for testing different situations according to our logic.

For ex :

void main()
{
  	int A=10,B=20;
	if(A>B)	// conditional expression a>b can be true or false only.
	{	
		print("A is greater than B");
	}else{
		print("B is greater than A");
	}
}

As booleans can have only true or false values. General purpose usage of boolean data type is to evaluate the conditional expressions.

So, if A>B is true then condition satisfies and your program execution enters inside if branch, otherwise program execution moves to else branch.

So, in this way you can Implement Boolean data type anywhere in the programming code to check conditional expressions.

Practice with so many conditional Program definitions to be more familiar with the Booleans.

Feel free to ask your questions in the comment section. Keep reading and commenting your suggestions to make toastguyz a better site to learn different programming languages.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Show Buttons
Hide Buttons