In this lecture.
You will learn about the boolean types here.
Boolean types have two states.
True or false?
The sole boolean type is bool, so integer types and the bool types convert readily.
The true state converts to one.
So true equals to one, but the zero so false equals to zero.
Also any non-zero integer converts to one.
And the nonzero one and the zero converts zero to 0 or 0 equals false.
So in integer types here.
Integer to boolean.
So we have a boolean literals here.
So to to initialize boolean types you use to boolean literal either true or false here.
My bool boolean equals you can assign this true or false.
That's.
Here.
So we have a format specifier for Boolean as well as other variables.
The format specifier for boolean is D, there is no format specifiers for boolean actually, but you
can use the integer format specifier.
D within the print f to yield a one.
For true and zero for false.
The reason is that the print f promotes any integral value smaller than an integer to an int.
So here, let's create an R code that illustrates how to declare a boolean variable and inspect its
value.
So so before it, I want to show you some illustrations here, which I got from the Internet, Google
Pictures.
So we have you will learn about the logical and and or tables in later in this lectures actually.
So you will learn about the let me open the separator.
So we we are now learning about the operators.
As you know there is a six operator types in C plus plus.
Now we'll we are learning about the logical operators of C plus plus and which actually you already
know, arithmetic operators.
Now we are learning about the logical operators after that assignment, bitwise, relational operators
and other operators.
So.
And this is the arithmetic relational, logical bitwise, increment decrement and assignment operators.
So now we are learning about the logical operators with Boolean numbers.
So.
Here.
This is the logical operators as well, which you will learn here.
So let's create our code and I will explain all of these details later.
So let's create an BOOL number.
Bool P1 True.
I will explain all of these codes later as I'll as I always do.
Bull B two equals false.
And the print f.
Yeah.
Let's use our own format.
Specifiers d d and new line gave this as variable b1 b2 as you know.
Now this B1 goes to the first format specifier and B2 goes to.
Second former specifier, which you know already.
But I want to wanted to mention it and let's compile it our code.
Here.
Please see.
See Main.cpp here and exit.
The first variables, which is the one, comes through because as I said, if there's a one, if the
integer is one, then this true.
If the boolean is true, then integer is one.
So it showed us the one and b two is false.
Because of that zero it showed us zero and console.
Uh, so in bool with Boolean, it automatically comes to the comparison operators because that's what
Booleans are about, right?
The operators are functions that perform computations on operands.
Operands are simply objects, logical operators you will see in later lectures.
So in order to have a meaningful examples using bool types, you will take a quick look at comparison
operators in this lecture and logical operators in the next so you can use several operators to build
boolean expressions.
The comparisons.
Comparison operators take two arguments and returns a bool so the available operators are equality here.
Equality in equality.
So let me write that down here so I can share it with share with you in our lectures, um, downloadable
sections, so you can download it and use it in your own compiler.
So this is the equality.
Uh, equality.
And this is inequality.
And then here.
Here it comes.
The here it comes.
The greater than.
Then less than.
Less than and greater than.
Or equal to.
Greater than.
Or equal to.
Three.
It's like a math operators write you which you learned in middle school, I think.
Or.
Greater than and less than.
Ops greater.
Not greater than here.
Greater than or equal.
Two and here is less than less than.
Or equal to.
Here.
So.
Let's create an example program about this.
Which year?
Let's print something here.
Seven equal.
Equal sign.
And seven here.
I will explain all of this code later.
Seven equals equals.
Oops.
Not like that.
Okay, Um, new line.
Seven equals equals seven.
Here.
It will show us the numbers about that.
This is a true or false, which I will explain later, as I always do when writing some codes.
Inequality Sign.
So I don't want to just drink my lectures time.
So I will pause this lecture here.
So after that, um, like I have to write like, uh, 5 or 6 lines of code or whatever.
This is just.
This will be quick enough.
Um, so I promise this will look quick enough.
So you watch here and learn.
This is the unique inequality sign.
Not equal to seven.
Print f.
Printf here.
Ten greater than 12.
What in 20 years.
And this call.
And greater than 20
print f.
Ten greater than or equal to 20.
Here.
New first format specifier for integer and boolean.
In here and.
Ten.
Greater than or equal to 20.
Here and print f.
Ten.
Less than 20.
Format Specifiers always and new line.
Ten.
Less than 20.
Okay.
And last line print f.
20 less than or equal to.
20.
Format specifier.
New Line.
And our compare.
Our real comparison.
So these are the just texts.
So you can you can.
Don't write.
You can also don't write this text in this print function but wanted to write because of that.
I want to show you how these comparison operators works with illustration here.
20 less than or equal to 20.
Here.
So let's compile our code now.
Clear.
GCC main.cpp dot x.
Here, as you can see here.
So.
Um, each comparison here, each comparison here produced a boolean result here.
So and the print statement prints the boolean as integer 1 or 0.
So let's look at this code and our output here.
So seven is seven equals to seven.
Yes.
And this is the true.
And the compiler gave us one is seven is not equal to seven.
No, because seven is not.
Seven is equal to seven.
And this is false.
So this gave us compiler gave us zero.
Is ten greater than.
20.
No, because 20 is greater than ten and this gave us zero.
Is ten greater than or equal to 20?
Again, no.
This gave us the zero.
So false is ten less than 20.
Yes, so true.
This gave us the one here, as you can see here.
So is 20 less than or equal to 20?
So the answer is yes.
So true because 20 is not less than.
But here we have the second operator equality sign.
So 20 is equal to 20.
In next lecture, you will learn about the logical operators.
So I'm waiting you in the next lecture.