C Programming Fundamentals
Transcript
Hey, welcome to Giraffe Academy My name is Mike in this course I'm gonna be teaching you guys everything you need to know to get started in the C programming language C is an awesome programming language and it's actually one of the oldest programming languages around in fact A lot of modern programming languages are based off of C so it's a really good idea if you want to get into C or even if you're trying to get into something like C++ to learn the basics and in this course, we're gonna cover everything you need to know I'm gonna talk to you guys about installing a text editor and using the C compiler and we're gonna write some basic code I'll talk to you guys about you know, what is a program and how the program's work and how does C Read the instructions that you give it and we're gonna get into some more advanced stuff We're gonna look at things like if statements and loops we're gonna create different variables
We're gonna talk about the different types of data that you can use and C then we're gonna get more advanced We're gonna talk about things like structures and the functions. We're going to talk about pointers And basically I'm just gonna give you a full overview of all of the core concepts in C So by the end of this course, you'll have a really good understanding and a really good foundation Which you can build on you can kind of go forward and learn some more I'm really excited to be bringing you guys this basic course on C I'm really excited if you guys to dive in and start using these tutorials So feel free to click around through all the videos and hopefully you'll learn something awesome about C
In this tutorial I'm gonna talk to you guys about getting everything set up to start programming in C now in order to program in C We're actually going to need two things The first thing we're gonna need is an environment where we can write our C programs Now there's a bunch of these different environments. Essentially. All you need is just a text editor so anything that can you know, allow you to Write text and then save that text in a specific file format is gonna work although when we're working with C a lot of times it can be useful to use a special environment called an IDE an IDE stands for integrated Development environment. Basically, this is a special text editor which makes it a lot easier for us to write our C programs And so I'm gonna show you guys how to install an IDE called code blocks the second thing We need to write our C programs is going to be something called a C compiler now C is a programming language It means we can basically write out
You know instructions that we want to give to the computer but eventually for the computer to be able to execute those instructions they have to be Compiled which basically means like translated or transformed into a language that the computer can understand So we're gonna basically download and install a special program that will do that for us. So let's get started I am going to come over to my web browser and I'm just gonna go up to the Google search bar. And I'm gonna search for a program called code block. So just type in Code blocks C. And this link should come up. It's code blocks org now This is an integrated development environment It's basically a text editor that will make it really easy for us to write our C programs. So I'm gonna come down here into downloads and There's a bunch of options here one says download the binary or at least download the source code
We want to click on download the binary release. This is going to be the easiest option So if you're on Windows or Linux or Mac, you can install it from this page So depending on the operating system that you're on you want to click that. I'm on Windows So I'm gonna come down here to the windows option. You'll see there's little options for us to download this stuff So there's a bunch of options here. What we wanted download is going to be this one right here. It says code blocks And then the version number and then it says min GW - set up Basically what this is is it's gonna allow us to install code blocks So we're gonna be able to install that IDE program, and we're also going to be able to install AC Compiler. So remember I said we needed those two programs We needed those two things and this is actually going to give us both of them on Windows So I'm gonna come over here and click on the link to download this from sourceforge.net
And you can see it's gone ahead and downloaded that So now let's head over to our downloads folder and I'm just gonna double click on this setup program so this should open up a window where we can set up the program and Let's just click through this So I'm just gonna click Next I'm gonna agree the license and basically just leave all the options as default and you should be good to go alright when that's done installing it's gonna ask us to run code blocks so we can just go ahead and do that and It's giving me this little window here. It says compilers auto detection So you can just click on the one up here. That's highlighted It says GNU GCC compiler and I'm just gonna click set as default and click OK and there you go We now have code blocks installed so in the next few tutorials We're gonna be learning about setting up code blocks writing our first C programs and really just getting started with C But for now, you have everything you need to get started
In this tutorial I'm gonna talk to you guys about getting everything set up to start programming in C on OS X So if you're using a Mac Then this video will basically show you how to get everything set up in order to start working with C We're actually going to need two things. The first thing we're gonna need is a text editor basically We're going to use the text editor to write our C programs in and you can use any text editor that you want to write C programs but there's actually a special type of text editor which is called an IDE and it stands for Integrated development environment and it's basically a special environment where we can go to Write and run and manage our C programs So that's the first thing the second thing we're gonna need is what's called a C compiler now C is a programming language So essentially what we're doing when we're using it is we're writing instructions for the computer but in C
We're writing instructions that us humans can understand and work with but in order for the computer to be able to carry them out they have to be compiled or Translated or transformed into a language that the computer can understand and that's what the C compiler is gonna do It's gonna take our C programs and essentially just translate them to a language that the computer can understand So the first thing I'm gonna do is show you guys how to install that compiler and then we'll get a text editor So what you want to do on your Mac is go over to the search bar and you're just gonna type in terminal and Click enter and a window that looks like this should pop up now The terminal is basically a program that allows us to interact with the computer using text commands So we're actually gonna need to use the terminal in order to do what we want to do so the first thing we want to do is check to see if you might already have AC compiler installed so in certain circumstances
You might already have one. So you just want to type in C C - V and click enter and You'll see over here. I have AC compiler installed. So I'm getting all of this information. You can see over here It says like si Lang and it's giving me you know, a bunch of information If you have that, then you have your C compiler installed and you're ready to go But if you don't have that I'm going to show you guys how to get it So all you want to do is just type in Xcode select and then the space - - install and Click enter and you'll see I'm getting an error here because I already have these command line tools installed But if you don't already have them installed and obviously then you wouldn't have that C compiler Then this is gonna go off and install everything. You need to get that C compiler working so once you run that Xcode select command just type in CC - V again and You should be getting this version number
Alright, so now that we have our C compiler installed What we want to do is download an IDE So we want to download a special text editor that we can use to write our C programs in so I'm gonna go over here To my web browser and I'm up here at a website called code blocks dot org, and this is an IDE called code blocks It's one of the most popular free IDE s for programming and C. So we're just gonna come down here to this downloads link and There should be a few options here download the binary released download the source code. We're gonna click download the binary release and You'll see down here We have a bunch of options for windows linux and mac click the mac option and if we come down here You'll see that here is what we need to install code blocks on the Mac So if you go over to the right side here, there's a link to SourceForge where we can download it So I just clicked that link and it should start downloading
Automatically when that finishes downloading, let's head over to our downloads folder and you'll see here we have our zip file so I'm just gonna double click on this and They should give us code blocks now All you want to do is just drag and drop code blocks into your Applications folder and you're ready to go So you have code blocks installed and ready to start following along with this course and writing some awesome C programs In this tutorial, I'm gonna talk to you guys about getting our first C file setup So we're gonna load up a C file and we're gonna be able to get everything working and test out our program so I'm gonna open up my codeblocks program and this is the IDE that I'm gonna be using for the rest of this course So I'm just gonna double click on it and it should start opening once we have codeblocks open. You'll see over here
There's a bunch of different options like create a new project open an existing project So we're actually going to want to create a new project So whenever we're gonna start writing some C files We're gonna want to create a new project in code blocks so you can either click this button right here, or you can go up to file new and projects so either way it's gonna bring you to this window over here and There's gonna be a bunch of options here basically Just these are different types of like C projects that we could create what we're gonna be doing is creating a console application This is like there's a basic C project that you can run on your computer. That's exactly what we need So click on console application and then click go and I'm just gonna click through this wizard and you'll see over here. It says
C++ or C now C and C++ are both Different programming languages for this course, we're gonna be working with C So just highlight C and click Next and we're gonna give this a title I'm just gonna call mine draft and we're gonna have to put this project Inside of a folder so I'm gonna open this up and I'm just gonna put this on my desktop. So let's click OK and Click Next and you can leave all of these options as the default and we'll click finish so now what we should have is our first C project in code blocks now over here inside this little File Explorer you'll notice that Draf is right here. So that was the name of the project that I just created down. Here. We have this source folder So I'm going to click down and you'll see we have this file here called main dot C And this is a file that got automatically created for us by code blocks I'm just gonna right click and open it and you'll see over here. We have some default code so up here
There's these little lines of code that say include down here. This says int main so this is the Program that we're given by default when we created our C project and this is sort of like the simplest C program that you can Right, essentially what this program does is it prints out hello world onto the screen So in order to run this program and test it just to make sure that everything's working I'm gonna come up here and you'll see that there's this Green play button over here and it just says run when I hover over it when I click this button This file that we have open right here main see is gonna get run So we're essentially telling code blocks to run this file and execute the program So when I click the Run button, we're getting this message. It says the project hasn't been built yet do you want to build it like yes, and Now over here this little window pops up
Basically, this is the command prompt. So whenever I run a C program this little window is gonna pop up So if I was to exit out of this and run this program again You'll see this window pops up again. And it basically just executes the program and in the case of this program All we're doing is we're printing out Hello world onto the screen and that's actually what this instruction does over here. When we open up this command prompt. It's essentially just Executing the program and it's printing out whatever we told it to print out So it's printing out hello world over here and printing something out onto the screen is really easy And that's one instruction that we can give to the computer But as we go through this course we're going to learn all sorts of instructions that we can use but the purpose of this tutorial was just to get our C project set up and to test our main dot C file So as long as everything works here and you're good to go and now we can start really learning how to program in C
In this tutorial I'm going to talk to you guys about the basics of writing a program in C So if you've been following along with the course up to this point, we've installed a text editor We've installed a C compiler and we set up our first C program. And our first C project Inside of code blocks. So now essentially what we have is this file over here. This is that main dot C file I just kind of want to point out a couple things that are in here first up here We have these little instructions which are just called include and I'm not gonna get too much into what those do in this tutorial Later on in the course. We're gonna talk about what these are actually doing and the specifics of you know, How they're helping our program, but for now just know that in order for us to use our program We're gonna need to have these guys up there next thing we have is this little block of code called main and
It just has this name main you can see there's an open and closed parenthesis And this is actually what's called a method and don't worry too much about what methods are we're gonna again we're gonna talk more about those in future, but essentially a method is just like a container where we can put some of our code and This method main is very important because this is the method that's going to get executed when we run our program so in C we can actually write out a bunch of instructions for the computer and then we can run our program so we can tell the computer to Execute those programs and whenever the computer executes our C program It's gonna look inside of this main method in other words that's gonna look inside of all the code inside of these open and close curly brackets and it's gonna Execute that code so I have this instruction here It's called printf and basically this is just printing out some text onto the screen when we run our program
It's gonna come into this main method and it's gonna execute all the instructions inside of here namely this printf method So if I was to run my program then this is gonna work now Let's talk about actually running a program whenever we want to run a program that we write in C We actually have to do two things The first thing we have to do is what's called building a program or compiling a program And basically what that does is it takes all of this C code It translates it into a language that the computer is going to be able to understand and execute So it's essentially taking this C program code Translating it into computer code and then the computer can execute it and run our program So the first thing we have to do is always build our C file The second thing we have to do is run the file that gets built so once we've built this program we've compiled it down into code the computer can understand we have to run it basically tell the computer to
execute that code and in code blocks It's actually really easy to do this. So we can come over here and this little gear icon will allow us to build our program and then this play button will allow us to run our program but a lot of times when you're Programming you're gonna want to build and run your code at the same time, right? you're just gonna want to build it and run it just to see what Happened, you know? see how your program did So we have this option over here called build and run and this will both build your program and run it at the same time So generally as you're going through this course you're gonna want to be using this option That's build and run options when I click this it'll essentially build my program run it and then it'll show up here on this little window in this little window is basically a Console window you can call it. So a lot of people would refer to this as the console and
It'll just like output any Information that we tell it to so if we write a C program that doesn't output information that doesn't print anything to the screen Then we wouldn't actually see this but since we're using this printf command, that window is gonna pop up So let's talk about how these programs actually get executed essentially when we write a program We have a set of instructions So when I'm writing a C program, I'm basically writing out a set of instructions imagine you were writing like a recipe or something Right a recipe is essentially just a set of instructions that when executed correctly will result in You know cooking or baking something delicious, right? And that's basically what these C programs are It's a set of instructions that when executed correctly will result in the computer doing something for us and one of the cool things about
computers is that we can program them to do anything and C is one of the best languages to do that with so let's look at this instruction over here It's called print F and this prints something out onto the screen. We will notice over here at the end. We have this Semicolon and this semicolon is actually really important So whenever we write an instruction in C We always want to end it off with a semicolon That tells C that we're done with that instruction and we want to move on to the next one so I could actually copy this instruction and I could paste it down here and Now we're basically going to be executing this instruction twice so if I was to run and build my program you'll see that we're not only printing it out once but we're also printing it out twice So when we run our program the program comes down into this main method and it looks at all the instructions inside of it
So it starts with this first instruction. It executes it, right? So it prints out hello world onto the screen and then it also prints out a new line So this backslash n is like a newline character and that'll move the text onto a new line When it's done with this instruction, it moves on to the next instruction and it'll execute that instruction So as we go forward and we learn how to write in C We're gonna learn more and more complex instructions And we'll be able to use all those instructions in conjunction with each other to specify some seriously complex programs but for now This is really the only instruction that we know which is printf so why don't we use this printf? Instruction in order to draw out a little shape onto the screen So I'm going to show you guys how we can draw out like a little triangle onto the screen
I'm gonna take this printf and I'm actually just gonna get rid of hello world and I'm gonna copy this a couple times so I'm just gonna copy it and we'll paste it down here, maybe four times and What I can do is I can specify Instructions to the computer that will tell it to draw out a particular shape So down here I could make like a forward slash and over here We'll make another one and I'll make another one and I'll make another one and you can see here I've drawn like a little diagonal line with these forward slashes. Now, I'm gonna draw vertical bars going all the way down So I'm gonna put one here I'm gonna put one here. I'll put one here and finally, why don't we draw some underscores and then we'll put one so I'm basically drawing out a little triangle shape and these Backslash ends are just printing out a new line. So anytime I print this it's gonna move it on to a new line So it'll print this guy out now on the line down the line below
So if I was to save my program and execute it now the computer is going to go through it's going to execute each one Of these instructions in order and we'll be able to print out the shape onto the screen. So let's do that You see over here. We get our shape and One thing I really want to stress. Is that order matters? So if I took this instruction and I placed it up here as the first instruction now This is gonna get printed out first So when I run my program you'll see that we're printing out this kind of Funky looking shape and that's because we changed up the order of the instructions So the computer changed the order in which it executed those instructions and you'll notice here again, we're using this Semicolon after each line of code. So that's kind of the basics of writing a program That's essentially all you need to know when we're writing a program
we're specifying a list of instructions that we want the computer to carry out and Depending on which instructions we give the computer and which order we give them and how complex the instructions are That'll determine what the program does and as we go through this course, we're gonna learn more and more complex instructions we're also going to learn how we can take simple instructions like printf and Do different things with them to make our programs a lot more powerful? In this tutorial I want to talk to you guys about variables in C Now when we're using C programming language a lot of times we're gonna be dealing with data so there's gonna be different data values or different information that we're gonna want to keep track of and use inside of our programs and Sometimes it can be difficult to maintain and keep track of all that data and that's where variables come in a variable is
Essentially a container where we can store different pieces of information so different data values we could sort of things like numbers or texts or characters and These variables make it a lot easier for us to keep track of and manage all the data in our program So I'm gonna show you guys basically how variables can be useful and how we can use them in our C programs But down here. I have a very basic program. I'm basically just Printing out a little story. It says there once was a man named George He was 70 years old. He really liked the name George but did not like being 70. So this is a simple program We're just printing out a bunch of different lines of text and then when I run this program You'll see we print out the actual story so over here we have our story and this is great But let's say that I'm reading through my story. I'm reading through my program and I'm thinking to myself hmmm
I think I want to change the character's name So instead of calling the character George, why don't we call him like John in order to make that change? I'm gonna have to look through my entire program and find every place where we mention the character's name So right here is one change it to John remember keep looking and here's another one. So we'll change this to John, right? So I had to manually go through and change every instance of the character's name To John and let's say that okay. That sounds pretty good But maybe I'm thinking I want to make the character a little bit younger. So instead of 70 Why don't we make him 35? so now again I'm gonna have to look through my entire program find every place where we mentioned the character's age and change it to 35 So there and there there you go I changed the program I updated and modified it now
If I was to run this program then all that information will be updated and we'll have new story. Here's the problem though I'm dealing with a very short story. I mean, this is four lines We only mentioned the character's age and name twice But imagine if I was writing out a huge C program that had hundreds of lines in this story So story had hundreds of lines and maybe we mentioned the character's name hundreds of times. They're mentioned their age hundreds of times Well if I wanted to change the characters age your name? I would have to go through and manually change it in every single location that would take forever and it would be a huge track Basically, that's not a good way for us to manage and maintain the data and our programs All right. We basically have two pieces of data that we're working with Consistently in this program the characters age and the character's name
What I want to show you guys now is how we can use variables to better keep track of and manage these pieces of information So remember a variable is basically just a container where we can store some data so I want to create two variables which will store the character's name and The character's age and I'll show you guys how this can make our program a lot easier to Manage up here above these print statements I'm just going to make a new line and I'm gonna come over here and I want to create a variable Now whenever we create a variable in C, we have to give C a couple pieces of information So we have to basically tell C a couple different things The first thing we have to tell C is what type of information we want this variable to store now I'm gonna get into the different data types that we can represent and see more in the next tutorial
but for now just know that there's a bunch of different types of data that we can store and C we can store things like Numbers characters we can store text we can store decimal numbers all sorts of stuff like that in our case I'm going to store the character's name and the character's name is basically just a collection of characters So in order to create this variable The first thing I have to do is tell C that I want to create a variable that's gonna store characters So to do that, I'm just gonna type out char just like that and that'll basically tell C Hey, we're gonna store characters inside of this variable After we type out char I want to type out the name of the variable that I want to create Remember of variables that contain and it's a good idea to give these containers Descriptive names and those names will basically let us know what that variable is storing inside of it. So I'm gonna call this
Character name and now what I want to do is I basically want to store multiple characters so over here I'm telling to see that I want to store a character But in C we can also store instead of just storing like one single character we can store a bunch of characters and that would be kind of like you know a name so there's like four characters in here in order to store a bunch of characters inside of this variable after we Type the character Abel's name We're gonna have to make an open and closed square bracket And that's gonna tell C that we want to store a bunch of characters inside this variable So I'm gonna type char a character name open a close square brackets. I'm gonna set this equal to something So I'm essentially assigning a value to this variable and I'm just gonna make an open and closed quotation marks and inside of here We're gonna type out the value that we want to store
So in my case, I'm just gonna store the character's name, which is John and then as always in C We're gonna have to end this off with a semicolon All right so essentially what I did here was I Created a variable and I told C what I wanted to store in the variable I wanted to store a character. I gave this variable a name. It was character name and I used these open and close square brackets to sell C that I wanted to store a bunch of characters. Not just one Now what we can do is we can make another variable to store the character's age So in this case, we're gonna want to do something similar, but we're gonna want to store a number There's a bunch of different ways that we can store numbers and see but for our purposes we're storing a name so we're gonna use something called an integer and an integer is basically just a whole number so I'm just gonna type out int and
That basically stands for integer. And now we're gonna give this a name so I'm gonna call this Character age and I'm gonna set this equal to a number So in our story the character is 35 So I'm just gonna type out 35 and now we can again end this off with a semicolon So I have two variables here. This one's storing a collection of characters. This one's storing an integer Now the question becomes how can we use the inside of our program? well basically What we can do is we can print them out alongside of this text and we can actually use this print F Instruction in order to do that so I'm gonna show you guys how to do this and then we're gonna talk about it So basically, I'm gonna go over here where we have the character's name I'm gonna erase this and I'm gonna replace it with a % and an S and now over here I'm gonna make a comma and I'm just gonna type in the variable name. So I'm gonna type in
character name and basically what's happening is when we use this percent s We're telling see that inside of this string of text here We're gonna want to insert a another String and a string is basically just a collection of characters so I could call this up here a string variable So when I say % s this is basically a placeholder and I'm telling C I'm gonna insert a string into here and Over here I use this comma and then I type out the string that I want to include so in our case
It's character name and so basically over here It's gonna say there once was a man named % s and it's gonna replace % s with whatever we specify over here So it's gonna replace % s with the value that's stored inside that character name variable so I'm gonna save this and we'll run our program and Now you'll see that it's still printing out there once was a man named John Even though we didn't actually type out John over here We just typed % ass in the character name so I can do this in this other spot too. So down here We're also using the character's name so I can type % s and over here we can type
Character name and again. This is going to act as a placeholder For this string of characters that we specify over here Let's do the same thing with the age so over here we have the age is 35 I'm going to do something similar and I'm gonna say percent but now because I have a number instead of using percent s I'm gonna use Percent D and that basically means that we're gonna insert an integer number into here So I'm saying he was percent D years old and over here. I'm gonna make , and I'm just gonna type out the name of the variable that I want to be placed inside of here so I'm just gonna be Character age and we're going to do this one more time down here. I'm going to type percent D and
Character age so essentially what I'm doing is I'm printing out the value That's inside of character age where I specify this placeholders so Let's go ahead and run our program and now you'll see it's gonna look exactly the same as it did before it's the same story the same name and the same age Except I didn't have to actually type out the character's age and the character's name inside the story I just referred to the variable and what's cool about? Variables is I could come up here and let's say I wanted to modify the character's age all I would have to do is modify it in this one spot so we could change the characters a name to like Tom and We could also change their age to like 67 And now when I run my program all of that's gonna get updated in the story so now it's using the name Tom and the age of 67 in our case. We only mention the character's name and the character's age a couple times
But you can imagine if I was mentioning this variable like ten or twenty or thirty times Having to change it in each one of those individual spots would be extremely difficult So variables are great because we can store the value one time and then if we want to modify it We just modify it in one place. So another cool thing that we can do with these variables is we can actually modify them So let's say that halfway through the story. I wanted to change the character's age. I could actually come down here I can make a new line and right above these print statements. I could give this variable a new value so I could say character age and I can just set it equal to something else so we can set it equal to like 30 and Again, we want to include that semicolon. So now halfway through the story. The characters age is actually gonna change
So you'll see it says there once was a man named Tom, he was 67 and then down here The age is being a 30 so we actually modified the value that was stored inside of the variable Halfway through printing out our story and that's really why variables are useful So that's kind of a basic overview and introduction into what variables are why they're useful how we can use them And over here again, we're storing a collection of characters, which is called a string and we're also storing this integer But there's some other data types that we can also represent So in addition to representing like a string or a number we can do some other stuff as well And I'm going to talk about that in the next video But for now, this has just been a basic overview and introduction into variables and see
In this tutorial I want to talk to you guys about data types in C and in the C programming language We're gonna be dealing with a lot of data So generally when you're writing programs, you're gonna be dealing with all sorts of information and in this tutorial I just want to talk to you guys about what types of information we can represent and use Inside of our C program and these are called data types. All right So what are the different types of data that we can work with in our program? So I'm gonna show you guys all those different data types right now So a lot of times in C when we're working with data, we're gonna be storing that data inside of variables so I'm just gonna show you guys a bunch of different variables that we can create and all the different types of data that we Can store inside of those variables? so remember whenever we create a variable and C we have to tell C a couple pieces of
information and the first piece of information we need to tell C is what type of Data that we want to store inside of that container inside of that variable so let's talk about the different types of data One of the most basic types of data and probably one of the types of data you're going to be using the most Gonna be numbers. There's actually two very important types of numbers that we can represent in C So the first type is called an integer and an integer is basically a whole number so it's a counting number right if I was counting on my fingers 1 2 3 4 5 I'm just counting out whole numbers and I'm not saying like 1 1 and a half to 2.3 like I'm counting in whole numbers and that's what an integer is So to create an integer we could just say int And we'll give this a name so we could say like age and we could set age equal to like 40 or something Now whenever we want to use an integer in C. We always just want to type out the number
So you'll notice I'm not putting quotation marks or parentheses or anything around this I'm just typing out the number like that. And now we actually have our variable age another type of number we can create is a Decimal number so this would be a number unlike an integer So it would be like 2.5 or eight point six seven or seven point five three eight, right? It's a number that has a decimal point associated to it. So there's actually two types of decimal number in C there's something called a double and there's something called a Float, and I'm not gonna get too much into the difference between the two of them But as a beginner to see for the most part You're just gonna want to use a double So I'm just gonna type out double and this could be like someone's GPA. For example, it might be like a
3.7 or whatever so, you know, you can use the double to represent decimal numbers it's also important to note that I could also represent like the number three so I could just say like 3.0 and that's gonna be a decimal or I could say 40 point O So the difference between 40 and 40 point O is that forty point O is a double It's a decimal number and 40 without the decimal point is an integer So that's something just to keep in mind so you can make this like three point six So those are the two basic types of numbers integers and doubles and those are gonna come in handy all the time Now the next type of data that we're gonna want to store or is gonna be characters So in C we can store single characters inside of a variable so I could just say CH AR and that stands for character and we could give this a value So maybe it'd be like someone's grade and when we create a character in C
We're basically going to specify the character that we want to store inside of single quotation marks So inside of these single quotation marks, I could put a letter I could put like a a lowercase a we could put h C d AF basically you can put any character that you want to store So if I put an A here now, this character variable grade is gonna store the single character a inside of it It's important to note that you can only store one character so I couldn't put like a whole bunch of characters over here And that's actually gonna throw an error All we can do is store one single character, but these three are the basic data types in C So these are the basic types of information that we can deal with in our C programs and just using these Three data types, we can represent all sorts of information I also want to talk to you guys about one sort of extra data type and it's not
Technically a data type in C. It's technically like a modification of the character data type So you'll notice when we create a character we can only store one letter one single character inside of it But a lot of times we're gonna want to represent more than one Character so we're gonna want to represent like a string of characters and generally this is called a string so it's a collection of characters that are grouped together and we can use this char datatype in order to create a String so I can basically say char I can type out the name of the string that I want to create so I could say like phrase and then after this I can make an open and closed square brackets and this is basically gonna tell see that we want to string a bunch of characters together and What we're actually doing is creating something called an array and I'm gonna get into arrays later in the course But just for now know that we can create a string of characters by using char
Specifying the name these open and close square brackets, and then we can create this using to open and closed quotation marks So instead of these single quotes up here We're just gonna use double quotes and I could type in like a phrase so I could type in whatever String of text I want here and this will get stored inside of this Variable which like I said is technically called an array now It's important to note that Doing something like this or creating this like string of characters is a little bit different from these guys up here So like these variables up here we could modify them We can give them new values but you can't do stuff like that with this So just know that this is like a special type of data and it's gonna act a little bit differently than these ones up here But that's one of the basics of working with data and those are all the basic datatypes that we're going to be using in our C programs

Ask anything
We've read this whole study set, so questions about it get the best answers.