C Programming Tutorial 20 - Intro to Data Types - Part 2

submitted by mkenny400 on 03/19/18 1

There are also other data types you will come across. One example is an array. An array can be used to store multiple values in one data type. So we could make an array of integers, which would be a collection of integers, where each are called elements of the array.   We can also create a character array. A character is just an individual letter, number or symbol from the keyboard.   Now, an important type of data that every programmer needs to know is that of string. A string is a group of characters surrounded by double quotes. "I like cats" is an example of a string. How do we go about storing something like this in a variable in C? Well we actually use an array of characters. So think of the string as a collection of characters in a sequence. There is something special about storing strings in that you have to end them with what is called a null character. We'll get into all of the details later on as this is just an intro, but essentially, we have to make the array one element longer to store a fancy \0 character, which is called the null character, or null terminator.   Finally, another extremely important data type category we have are pointers. Pointers are an incredibly powerful tool in C that I hope to discuss with you guys soon.   We also have an important term known as constant. A constant is any value that does not need to be evaluated. So 5 is a constant, it's not some function call or some value that is retrieved from the user.   Another thing you are going to want to be familiar with is how to write constants. Now, the term constant has many meanings, so let me explain. Think of a constant as something that you can write the value of down. Certain constants are going to be interpreted different ways. When you declare a variable, you have the privilege of giving it a data type, so there is no confusion, but if you just write down a number, C has to interpret what type of data that is.   For example:   3/2 and 3/2.0 produce two entirely different results. That's because C treats the data a certain way depending on the data type of the constant value.   If you want to make a character constant, you have to single quote it, like 'k', but if you want to make a string constant, you use double quotes, like "pi$$a". You could also do something like "H", as this is a string with one character, not just a character…THERE'S A DIFFERENCE!   What's the difference between '3', "3", and 3? The first is a char, the second is a string constant, and the third is an int.   With numbers it's a bit more vague because there are actually a lot of different number data types and you don't have the difference between single or double quotes, because number constants do not use quotes. There are ways to be very specific when you want to tell C a constant is of a certain data type. For example, you can end a number with the letter F to say that it is specifically a float. Otherwise C assumes the constant is a double. But those terms may be foreign to you, so that's what we are going to be discussing 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)

×