C Programming Tutorial 28 – The bool Data Type

submitted by mkenny400 on 03/19/18 1

In the previous video we learned how to use the _Bool data type. I recommend you watch that video before you watch this one as it has fundamental knowledge that will help you here.   If you've noticed, it seems that all the data types in C are lower case. We have int, double, float, char, but this _Bool had to go ruin everything for us. Well, there is a way we can actually make this just bool. You first have to include a header file:   Now, we can declare a variable like this   bool calebIsFat;   Not only does this allow us to use the bool data type, but to make our lives easer we can use the words true or false rather than 0 or 1.   bool calebIsFat = false;   Yup, I exercised since the last video.   One important thing to note here is that the word false is not in quotes. We are not giving the variable a string with the word false in it. We are giving the value false with no quotes.   The way these work is no different than _Bool, it just makes it easier to work with. In fact, the values stored are still zero or one. Consider this example:   bool CalebIsFat = true; printf("%i\n", calebIsFat + 10);   This will print the value 11 because the value of calebIsFat is 1.   Now, there is not a format character to print true or false, so for now the easiest way to print this is to use the same thing in the previous video, where we just print it as an integer. This will still work where 1 = true and 0 = false.   Later, when we get into something called conditionals, we could write a program that would say Caleb is fat or Caleb is not fat depending on the value of this variable, but for now, this is good. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 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)

×