C Programming Tutorial 27 - _Bool Data Type

submitted by mkenny400 on 03/19/18 1

In this video we are going to be discussing Boolean data. Boolean data is anything that is either true or false.   Now, if you remember back a few videos ago when I started talking to you about binary, I mentioned how a single bit can be either 1 or 0. It works pretty similar with a Boolean variable.   To create a Boolean variable, we use _Bool (the B must be capitalized):   _Bool calebIsFat;   Notice the naming convention here. I have decided to lower case my name to follow what is known as camel-case naming convention. That is where the first character of the first word is lower case, but every word after that is upper case. Another common convention is to use all lower case with underscores to separate the words. Whatever you use is up to you:   _Bool caleb_is_fat;   Now, the reason I named this variable calebIsFat is not because he is, but rather that he might be. I'm not saying that Caleb is fat. I'm saying that the statement "Caleb is fat" is either true or false. This is the very foundation for what is known as Boolean logic, which you will find when you study discrete mathematics, computer engineering, computer science, and a ton of other cool stuff.   Now, we need to assign a value to this variable. This means we have to ask ourselves…Is Caleb fat? Well, I wouldn't go so far as to say I'm fat, but I could use some trimming around the waist. In fact, I had to buy new dress clothes for my videos because I'm so fat. Therefore, I am going to go with yes.   _Bool calebIsFat = 1;   To assign true to this variable, use 1 (which represents true). If you want to assign false, use 0. Actually though, if you store anything besides zero, it is stored as 1. This means that anything that is not zero is stored as true. So to express my fatness, I could do this:   _Bool calebIsFat = 9001;   Now my fat level is over 9000.   How do we output these values though? Well, you can output just as if it were an integer:   printf("Is Caleb fat(1 is true, 0 is false)?: %i\n", calebIsFat);   You can see that according to my program, indeed I am fat.   Now, this is cool and all, but some of this isn't very intuitive. Like, why is it called _Bool? You also have to remember that 1 is true and 0 is false, and it's just plain hard. I have good new though! There is an easier way to represent Boolean data, and that is what I am going to talk about in the next video. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Support me! www.patreon.com/calebcurry Subscribe to my newsletter: eepurl.com/-8qtH Donate!: bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: CalebCurry.com Facebook: www.facebook.com/CalebTheVideoMaker Google+: plus.google.com/+CalebTheVideoMaker2 Twitter: twitter.com/calebCurry Amazing Web Hosting - www.dreamhost.com/r.cgi?1487063 (The best web hosting for a cheap price!)

Leave a comment

Be the first to comment

Collections with this video
Email
Message
×
Embed video on a website or blog
Width
px
Height
px
×
Join Huzzaz
Start collecting all your favorite videos
×
Log in
Join Huzzaz

facebook login
×
Retrieve username and password
Name
Enter your email address to retrieve your username and password
(Check your spam folder if you don't find it in your inbox)

×