YTread Logo
YTread Logo

C Programming Tutorial 9 - C Basics Part 1 - Variables, Expressions, Statements

Apr 09, 2020
welcome back everyone, this is Caleb from Caleb's video maker 2 and this is his C

programming

tutorial

series. Now we're going to start covering the

basics

of C. Now we've made the Hello World program and I talked about the functions and all that good stuff, but now I want to teach you how to learn to write your own programs, so I recommend that you understand the general structure of the Hello World program almost to the point where you can write it yourself. It's okay if you have to reference some, but you want to. understand the general format of how to write a program.
c programming tutorial 9   c basics part 1   variables expressions statements
I don't think you have to sit there with note cards memorizing every single thing because honestly that will come with time, you just have a rough idea of ​​where to put what and where the semicolons go. In this video, the first thing I'm going to talk about is spacing, so where do you put the spaces and the C? To start, I'm just going to create a file job, we'll just name it, subscribe, dot C and let's get started. with basic formatting, so you'll want to get into the habit of writing this every time you write a program.
c programming tutorial 9   c basics part 1   variables expressions statements

More Interesting Facts About,

c programming tutorial 9 c basics part 1 variables expressions statements...

Now you can see I put some spaces here, there's a space here, there's a tab here and how do you know where to put it? those things, well luckily for us, C is a space-aware language, which means we can put space wherever we want, that means you could anyway write this like this or like this or like this or like this and everything will work exactly. Same thing just to try it out. I'm going to exit this and we'll compile this, as you can see, there are no compilation errors. Let's go back to our code and you might be wondering if you don't have to put spaces.
c programming tutorial 9   c basics part 1   variables expressions statements
Why did I choose to put spaces? So let's format this again now that I had it. We can enter insert mode by pressing. I let myself just clean this up. You know, the reason I formatted this is for clarity. I put a different separation. between the includes and our first function here, also, inside these braces is a block of code and by convention we indent everything in this block of code, so if I were to add another line here, I would also indent it like that manner. a clear visual presentation that both lines are

part

of this block of code, so now we know how to format things well, how do we go about encoding things well?
c programming tutorial 9   c basics part 1   variables expressions statements
The first thing I wanted to introduce you to when it comes to coding is

variables

. a variable is something that can store some data that can be used later in our program, so inside here we can create a variable by writing int X. Now the X is just the name of the variable. You can name it whatever you want. works fine, there are some conventions here, although for example I lowercase the first letter and capitalize each of the other letters, if you're just making a single variable like int This declaration here is called variable declaration. We're saying, hey, there's a variable called X, we're declaring that the variable exists, how exactly does the variable store a value?
Do you know what a variable is for if it doesn't store anything to give the variable value we need? variable initialization, so to do that, all we have to do is go down to the next line and say x is equal to 5 or whatever value you want to give it, the only thing is that it has to be an integer value because up here we said int so a the integer is an integer, think of 1 2 3 4 negative 5 23 anything without decimal points now a very important word that you need to know when it comes to computer

programming

is syntax syntax is form or format like where we put semicolons where we put equal signs and where we put all those other fancy symbols and stuff.
All of those rules are called syntax and you will become more familiar with C syntax as you start programming in C now that I have this variable X, let's talk about it. using this variable first let me get rid of this junk and then up here we're going to do some calculations. I know you probably love math most people, so we can just create a new variable and say int y equals x / - any time you see an X in our code like here, you can think about the value five and replace that x is equal to ten ten divided by two is obviously five, so if you were asked what the value of y is, well you could say five, the value of y is not the value of x is substituted here and then division occurs. and then it is assigned to the variable Y, so the variable Y only contains one thing and the thing it contains is an integer, as you can see here now.
You may have noticed that instead of using Well, if we're using variable X, you know, 10 or 20 times in our program, we're not going to do it. If we want to have to repeat the same value over and over again, we could give X a value like 10 and then simply replace those values ​​with the variable. Other times we might get the value of It's always best to use

variables

when any of those situations arise, the last thing I wanted. What I teach you in this video is the concept of expression, an expression is anything that can be evaluated and the result will be a value, so below we have an example of an expression X divided by two, that expression is evaluated as a value which is five, so we have the value five inside a larger declaration, so to summarize the keywords that we need to know our expression, declaration and initialization statement up here, you can see that we declare the variable and then we initialize the variable with the value down here.
We're actually doing both steps in one line, we declare the Y variable and then we give it a value of five. In the next video, we'll talk about how to get this to print to the console using printf. Everything so far makes sense to you and stay tuned. If you have any questions, be sure to leave a comment. I or some of the other viewers will be able to help you. Thank you. See you in the next one

If you have any copyright issue, please Contact