Interested in Personalized Training with Job Assistance? Know More
Hello everyone, my name is …..and we are continuing with this C programming course.(7 seconds pause ; music)
In the last video we had discussed, what are the data types used in C programming language.
Which means the variables that we make, in which we store the values.
What type of value that would be, which value will be stored in it?
Who told us all these things?
All these things are told to us by data types.
Whenever we are making any variables, in which some values will be stored, before that we have to tell its data types, exactly which type of values will be stored in that.
So, we have discussed these things in the last video, then we saw what are the different types of data types.
So, these are of four types.
First were basic data types.
In which we discussed ‘integer’, ‘floating point’, ‘double’, or ‘character’.
After that, we saw derived data types in which we discussed arrays, pointers, union and structure.
We will practically use all these in the coming videos.
After that we saw the Enumeration data type which means the custom output that we require in the program, which means with the help of the program we want to do something specific.
So, to do those specific things, we will require some custom data types, which means we will have to store customised values and data types, And enumeration data type helps in that.
So, this data type is a user defined data type.
Whenever in the program if we are using a custom data type, at that time we will make use of this.
After this, we saw void data type.
Like we have to make a variable but we don't want to put any value into it, we wish to keep it empty.
So, if we want to keep it empty, which data type should be given to it.
So, to that we give void data type.
Void data type means the value in it would be empty, which means that there will be no value stored in it.
So, we do this, when we have to make some variable into the program. but currently, we don't know which data type should be given to the variable.
At that time, we can make it a void data type so that later we can change its type.
So, all these things we have discussed in the last video after that we also used it practically and saw how we can use int, float and character.
So, after understanding all these things, we saw that variable has a data type.
So, we will discuss in this video, how exactly the variable works.
Why do we make variables and how do we make them, how do we store values in them, the answers to all these questions will be seen in this video.
So, without any delay let's start, we are looking at ‘variables used in c’.
So, we will see a simple definition which says that,
“a variable is a name given to a storage area that our programs can use to store values”.
So, this was the definition.
Now, we'll understand it in layman terms.
Like we had discussed earlier, the variable is a storage location in which we are storing a value and going ahead in the program, we are changing that value.
All these things, we have discussed in the previous slide but how is it getting stored, we will understand all these things now.
We know that inside our computer or laptop there is one hard disk or a hard drive in which basically our data is stored.
Any data you're storing or you are making any presentation or you're saving any game.
Where are all these things getting stored ?
They are getting stored in your hard disk.
So, you know that a few hard disks have a limit of 500 GB, some have 1 TB.
In this way, its storage is defined.
Like if you have to store a value in our program.
Suppose, we have to store a value 5.
So, where will it be stored?
We will know that it is stored in the hard disk.
But in which way the data is stored in the hard disk ?
There are small blocks that are made, our data breaks into pieces and gets stored into those blocks.
Whenever we want to get back that data, it comes out of the blocks, comes together and we get our data.
So, in this way, our data gets stored.
Are you getting it?
Now, what we will do is the 5 values that we have to store, which means number five which we had to store, we will give some name to our program, which means particular location or area, we will name it something inside our program.
Like we did here, r e s.
We made a variable r e s and we named it and we assigned 5 values to it.
It is getting stored in our hard disk, hard drive but that location area’s representational name that we have got in our program, that is r e s, that is variable.
So, any particular memory location or memory address, making its name, so that we can refer to it ahead in our program that we call as variables.
We have to give the name to our variable on our own.
Like we gave r e s, we could have given ABC, CBA, we could have given any name.
So, we had discussed in the previous video that, in which way identifier’s name is given, which means that there can be capital letters included in it, small letters also can be included in it, underscore can be included in it, digits also can be included in it but, the digit should not come at the start of the name.
Apart from that, there shouldn't be any blank space between the names and there shouldn't be any special character as well.
So, these were a few rules, with the help of which, we can make identifier’s names and our variable which is user defined, which means it is made by us.
So, we have to give it an identifier's rule and name it.
So, in this way, when we are making the variable, the rules that were there to give the names to the identifier, all those we will follow in this as well.
understood guys ! Perfect !
Now, we will go ahead and see which all types of variables are there.
We have seen ‘integer’, ‘float’, ‘double’, ‘character’, ‘void’.
So, these basic types of variables are there, which are used in the C programming language.
There are many apart from these but they are derived, which means these integers, float are there, the others are derived from it.
Like we had discussed in the previous video that there are few data types, these integers, float, double etc.
These are basic data types and the ones that are made out of these are called derived data types.
With these small pieces or with the same values of the integers, the big data types are made which we call as derived data types.
So, these variables would be of the same types like our data type, if it is integer, then,
Variable will also be integer type, if it is float then, our variable will also be a float type.
So, in this way, the variable has its same type like the data types are there.
So, all these things we have seen,
what is integer? It is represented with int, we had seen, the floating point numbers or the decimal, we represent them with float.
Then, we even represent double.
We had seen in earlier data types that the double uses four bytes of memory and after that character, after that we even saw void, how void is an empty area.
So, all these things, we understood in variables and data types.
So, these are our basic types of variables.
We will go ahead and see,
How we can declare this variable.
In our program, the variable that we are making,
how will we declare it? How will we tell our compilers that this is our variable?
It has a syntax, there is a rule to write it.
So, let's see what it is.
“A variable declaration tells the compiler where and how many storages to create for the variable”.
Now, what we will be telling in the declaration,
we will tell our variable’s name and along with that we will tell its data type,
which means what type of values can be stored in it and the name of our variable.
These two things, we will tell together in variable declaration.
So, generally, this is the task ‘before using our variable’,
which means that as soon as we are starting to write our program,
we know that as soon as we have to do the sum, which is addition of two numbers.
So, we know that we will require two numbers which needs to be added, third we will require one more variable where our value will be stored.
So, we know that we would require three variables inside which the values will be stored.
So, we will tell our compiler earlier,
that we will make use of three variables then after going inside the program we will use these three variables, the way we have to use it.
So, this declaration would be the upper part where we are telling the compiler that this variable will be used in our program, you can write it in different ways as well.
Like you have seen here in an example, there is float written, float is a type of data type and after float, ‘f’ is written and then comma is given and then salary is written and then semicolon is being given.
So, we can see it here, the f that is written here and the salary that is written, these two are different variables which have the float data type,
So, if you want to do anything of this sort, four or five as many variables you're making, all will have a data type that will be integer, what will you do,
you will write int only once.
After that, you will write the variable’s name with a comma.
like I have to make three variables which are called a, b and c.
What will I do, I will i n t, integer data type, after that I will write ‘a’ then I will put a comma and write ‘b’ again I will put a comma and write ‘c’ then, I will put a semicolon, with the semicolon, we will get to know that our statement or line has finished.
So, in this way, if I have to make many variables of the same data type, we can write them in one line.
Otherwise, what we would have to do is we would write i n t, then a, then put semicolon and then we would come down and write i n t ‘b’ and again we would put semicolon.
Then again, we would come down and write i n t ‘c’ and semicolon.
In this way, we would write one thing constantly.
So to not do this, there is another way of writing it where you have to write the data type only once.
And after that 2 or 3, how many variables are there, you have to put a comma before them.
So, these are few declaration types.
We will understand practically how it works !
And we will go ahead and see what is variable definition.
What would be the variable definition?
Now, we have told our compiler, these are all the variables.
What will definition do, it would be using the variable, which means it will store the values in the variable.
Like we saw in the declaration, we had only given the data type and its name.
In definition, we will see that particular variable, what values have been stored in it.
You can see here in the example.
I is basically a variable, in that, 43 is coming and being stored here, this equal to sign, which is a single equal to that you're seeing, what is this sign doing, it is making stored 43 in I.
After that semicolon is there, with semicolon, we will understand that our line has got over and even our compiler will understand that since the semicolon has come, the line is over.
So, this is the definition we saw, before that we saw the declaration.
Sometimes it so happens, that definition and declaration comes in one line,
with the help of which we don't have to write things over and over again.
How will that happen, we'll be seeing in our program.
clear so far !
So, we will further go directly to the practical and see, in which way, we can make the variables and handle the things.
Now, we have this 1st program where we
have seen data types.
So, this is a simple addition program.
We are adding 2 numbers, we are making an answer and printing it on our screen.
So, this is that program where we had seen with the hash, these are 2 preprocessor commands.
After that, from here, our main function starts.
This curly bracket tells us that from there till here, our main function will last.
So, we have seen these things.
After that comes this part,
this part of our variable declaration.
Now, we will see how it works.
You will see that num1 is a variable.
Even num2 is a variable and the result is also one variable.
So, these three are variables and we have declared them in one line.
Which means our integer data type was there.
So, we didn’t have to do it this way, I will show you in which way, we could have written it.
We would go up here and put a semicolon here.
After that we come down…
And then we again tell that the num 2 data type will be int.
And after that again we put a semicolon.
And then we put int and wrote the result.
In this way, what we are doing is, the thing that was written in one line.
We had to write in 3 lines.
So that we don’t have to write int frequently, in the three lines.
And the work is done in one line.
Why do we have to finish it in one line?
Since the lines which are there, you can see here that 15 lines have been used to get a two numbers sum done.
This we could have done in 6, 7 or 8 lines as well.
This int that is constantly written, removing this, we could have written int in just one line.
In this way.
Like we had discussed before, you write the first variable, then put a comma and write the second variable and then put the comma and write the third one and put the semicolon as it gets to know how our program is working.
So, here our variable declaration is done.
We have set its data type.
Clear, so far? good!
When we go ahead, we can see that num1, 2 is getting stored.
This is called variable definition.
Which means, we have declared here and told the compilers that these are the variables that will be used.
Here, we used them and how we used them, we stored our value in it.
We stored 2 in num1, we stored 3 in num2 and then, we applied addition formula here, which you can see, we added num1 with num2.
And then, we sent it inside the result.
So, this was the way of adding any two numbers.
So, you can see white dot here.
This means that this program or code has not been saved.
So, what you will do is you will go on file, click on file and here save option will come.
(pause 3 seconds ; cursor movement)
This is the save option.
You can use the keyboard shortcut and press Ctrl+S.
So, this is saved now, the white dot is not appearing.
Now, we will run it and see whether it is working or not.
So, we will right click and click on the run code.
As soon as we click on run code, we will see below that, our output will get printed.
Sometimes it takes time.
Here, we will see whether our output is getting printed or not.
(pause 2 seconds)
You can see here that our output has got printed here.
We had to mention num1 plus num2.
Its answer, 5 has been printed.
Sometimes it happens, we will remove this again.
And we will close this for the meanwhile.
What we will do here, int num1 2 semicolon.
We have removed this from here.
Here basically, I am trying to tell you how we can reduce the lines.
Which means the program that we are writing, how we can reduce its lines.
So, you can see here that declaration…which means making the variable and using it, both these things we have done in one line.
Where all our things were happening in 13 to 15 lines, now that entire program is completing in 12 lines.
So, in this way, we can reduce the number of lines.
So, you can see here, the data type also we gave in this line and in that value also we stored in this line, so with this our lines have reduced.
So, in int num1, we put 2, in int num2 we put 3 and we again made int as result and inside that we put num1 plus num2.
Then we have used this PRINT f statement, what does PRINT f do, it shows on the screen the output that we have to get.
So, what was the output we had to get the result?
This percentage d that you are seeing here, we will be understanding it in the next video, how percentage d is helping us to print our result, even that we will understand in the next video.
We just have to understand that the PRINT f line is our result, that is getting it printed.
Now what will we do here, we will quickly change the value, I have put 4 here and again I have put here 7.
Now there will be an addition of 4 plus 7, there will be a sum.
I have saved it with Ctrl+S.
I right clicked and went to the run code.
Here, you can see that 4 plus 7, it has 11 printed.
So, in this way, you can take different numbers and make a sum of it.
You can use the variables up or down, whichever way you want to use it.
Declaration, definition, you want to do it all together or differently, all these things we can see.
So, this was about variables, we understood it practically and saw what is the declaration and definition of one variable.
How it is being declared and defined.
And how it is used in one line.
All these things we got to know about the variable in this video.
If you have any queries or comments, click the discussion button below the video and post there. This way, you will be able to connect to fellow learners and discuss the course. Also, Our Team will try to solve your query.
Have a friend to whom you would want to share this course?