Hello everyone.
My name is Atharva Singh and we are continuing with this C programming course.
In the previous videos we had seen that why we have to use the C programming language, why we have to learn it? After that we saw how we can install or set up this C programming course in our system, computer or laptop.
That is the reason we had installed and set up both text editor and C compiler.
We had installed Visual Studio code as the text editor and GCC compiler as the C compiler.
In this video we will make use of both these things and we will start our first program.
Yes, the 1st program of the C programming language we are going to start in this video.
We programmers, before learning any programming language, the 1st program that we make in that language, that is one “hello world” program.
What does the HelloWorld program do? It prints a basic or simple statement on our computer screen or on our output screen which says, “hello, world!” this is my first program or this kind of hello world statement.
This Hello World program which is there, we will see this today in which way, by using which all things, we are able to print this statement in our C program.
So, for example, this would be our today's Hello World program, where you can see on the screen that we have got five to six lines and basically this “Hello World” program which is there.
What is it doing? This statement will be visible to you where it is written Hello comma world.
This statement that is there, this program will help us print this statement on our output screen.
In which way it will work, all those things we will see.
So, without any delay, we will start and see how the flow of our program is going.
Before starting this program, we will have to understand a few things, which are components of a C program.
Here we can see that with which all things our C program is made.
The first thing that we can see here is Preprocessor commands.
We will understand this in our coming up slides.
What exactly is a preprocessor command? But just to give you one glimpse, I will tell you that for example we have to make tea, the materials that we use to make tea, like milk, sugar or tea leaves, all these things we don't make on our own.
We directly purchase it from the market.
So, these raw materials that we have purchased for making the Tea.
These preprocessor commands are of the same type, they help us by importing some raw materials, which means some files in our program right from the start.
It includes them so that we can use those files in our program.
We will learn more about this in our coming up slides.
Let’s see what is the next thing in our C program, next are the functions.
What are the functions? Functions are also of that type where you have to get one thing done repeatedly.
What will you do? You will make a function of that thing.
So that in the coming times if you want to use the same thing in your program.
If you use only the name of the function there, rest of the things that you have to do will come there and get saved.
In this way you can use one thing continuously in your code or program with the help of functions.
We'll see more about this further.
Next, we will see variables.
We cannot see variables in this code example currently.
But I will give you the glimpse of even this.
What are variables? Basically, we give names to the variables.
Okay.
There are rules to give names to the variables.
Like we cannot give any names like we cannot start our variable’s name with a number.
Which means we cannot start our variable’s name with number one.
In the same way there are many other rules to name these variables.
What is the work of these variables? What is variable? Its works similar to its name.
Variable means its value keeps varying.
There are changes in the values.
In the variable we basically store a value.
Like I will take an example, I have taken a variable in my program and its name is “a”.
In this “a” I have stored some values.
Suppose I have stored 5 in a.
Now, what will happen? Whenever I have to change anything or any value inside this variable.
I can change it like I had put 5 before in a, now I will change it to 7 or 8.
As per my requirement I can change the value stored inside it.
So, this is the capability of the variables that you can change the values in it anytime.
After variables we will see what are statements and expressions.
You can see in this code example that one line starting with slash and star or there are lines starting from printf, these are the statements and expressions.
Here you can see that in this printf line there is a semicolon at the end.
So, the statements which are there in our C programming, basically they end with the semicolon.
With the semicolon we get to know that this statement has been ended.
In the same way these expressions are there.
Inside printf’s bracket you can see that there are double quotes used.
We have used them to write hello world.
So, this Hello World is also a type of an expression.
So, in this way with the help of statements and expressions also our C program is made.
After that at the end we come to comments.
Now, what is this comment? Comment is that part of the program which our compiler doesn't convert and tell the computer that you have to follow this action.
It means that you can see in this code example that the line that is starting with slash and star in which it is mentioned is my first program in C.
So, this is a type of comment.
This comment is for our reference and this C compiler that we have, it doesn't convert this line or this comment and tell our computer that you have to do all these things.
This is only for our reference so that we can get to know what is happening here in our program and accordingly what is going to happen going ahead.
With all these things our C program is made.
Now, we will directly switch and see the components of the program, like there is # included or int main.
What does all these things mean? After this as soon as we will understand all these things, we will straight away move on to the Visual Studio code, there we will run our program and see how the output of our program is being generated.
So, we will start and we will see the first line in our code’s sample which is our Hello World program.
What is there in it? It is # include, then there are squarish brackets given and inside that it is given STD IO dot h.
What is this line doing? This line is a preprocessor command, like I had given you an example of tea.
You don't have to make milk at home to make the tea or you don't have to make the tea leaves to make tea at home, you could directly purchase it from somewhere.
So, this #include command is like that purchase.
What is it doing? The file name that has been given inside the bracket stdio.h, apart from that there can be some other files like conio.h.
So, these different types of files that are there, this imports the #include statements in our program.
Why does it import? Because these files like the stdio.h there are a few things already defined in them which we have not made, which are made by a C developer and they are including that in our C programming with the help of this preprocessor command, with the help of this #include function.
So, this #include is helping us to import that file because this stdio.h has been already made by someone, so its functionality and its things we can use in our program as well.
That is the reason we are writing this # include line.
Now, you can see that this printf function that is there or mainf, the words that are written inside, even they keep some connection with the files that we have been included in the start.
We will also see that because of this we had to import that file first in the line.
So, you can see here, it is written that #include is a preprocessor command which tells the compiler to include the files beforehand.
So, the bracket that you're seeing in triangular shape in whichever file’s name would be there.
Our compiler will understand and import the file.
What does this preprocessor command do? It imports any file in our program so that we can use the things in our program going ahead.
Okay.
So, we have understood the first line, we understood that this # include thing that is there in our program.
What is that doing? Now we will be going ahead and see what is this int main? This is INT MAIN, you must be seeing round brackets ahead of it.
So, these round brackets, this main and this int, what does it do? Basically, if you take a small example, like you have a house and there is a main door to your house, the main entrance, through same door your family members enter and exit.
In the same way the entry point of our program is this main, MAIN.
So, in every C program you will see this main function and this will be the entry point for our C program.
From where our C compiler will start reading our code further and start converting it.
So, this is a main type of function.
How will we know that this is a function? Going ahead we will see what are these functions.
But if we want to know whether these things are functions or not.
How will we know that? As we can see that the main that is written here, there are round brackets after them.
So, with these round brackets we get to understand that this is a type of function.
So, we will understand it in this way, the main door of our house from where we enter and exit the house.
In the same way, this main function is the entry point of our program.
And from here our program gets started.
The lines that we have written over it which were the preprocessor commands.
We wrote those, so that we can tell the compiler that you have to include these files in our program.
After all these things our main function comes, the main entry point comes and we go into it.
So, how will you know that we have come into the main function? So, this is told to us by these curly brackets, you can see that after the names of the main function, you can see these curly brackets.
And they are going at the last and ending.
Which means opening curly brackets and closing curly brackets.
Whatever is written inside these curly brackets, it is the part of our main function and it is inside our main function.
As and when you will get familiar with the C programming language, you will practise it, you will start understanding these things more easily.
So, we saw what are the preprocessor commands, which was the first line in our code example.
After that we saw how this main function is working.
Now, we will go ahead and see this third line which is there, which is starting with a slash and an asterix, which means it is starting with the star.
What exactly does it do? The one that is starting with slash and star and ending with it, this will be ignored by the compiler.
The compiler will ignore this.
Why will it ignore it? Because this command is not for the computer.
This is for our reference.
The person that is writing the program, the person that is giving the set of instructions, it is for his reference.
So that you get to know what exactly you have told the computer to do in this part.
So, that is the reason why it makes it so easy for us to understand the program.
Because as you can see what is inside that slash, in that slash it is written my first program in c.
So, after reading this you can understand that this program is your first program in C language.
So, basically these comments that start with slash and star, we call these comments, as we have seen before.
These comments are ignored by our compiler.
It doesn't convert to tell our computer, it ignores them.
It is only for our reference so that we can understand what this program is doing in the particular area or in the particular section.
After that we will come to our fourth line of our program.
The printf line, what is printf? Even this is a type of function.
How did I get to know that this is a function? Because after the name the round bracket that you can see, those come.
Because of those I can get to know that printf is a function.
What does this printf exactly do? Before this I will tell you that this preprocessor command that I had written on the top, in which I had written that #include the stdio.h file.
This stdio.h file, what does this define? Why did we import this in the program? We have imported it so that the input and output things, the functionalities that are there or the program that is there, how will it handle our input things like our keyboard and mouse or how will it handle the output screen that will come.
All these things are defined in stdio.h file.
That is the reason why this printf function, which is the fourth line that you're seeing, inside which we have written this “Hello World” and even that we have given in double quotes.
So, this printf line, we have taken from stdio.h file.
Now you will be able to understand that since we have imported stdio.h file at the start itself, that is the reason why we could use this printf line.
And in printf line we have written in double quotes hello world.
We want that this Hello World should be printed on our output screen.
We will see how it is getting printed, you can see that after the Hello World we have given a backslash and n as well.
This backslash and n you ignore it for the meantime.
In the coming programs, ppts or slides, we will understand how these things work.
Ignore it for meanwhile, you only concentrate on the printf line which is starting with round brackets and inside that we have written HelloWorld.
And how is it ending? It is ending with a semicolon, as we had seen in the earlier slide that our statements end with a semicolon.
That is the reason why our printf line is ending with a semicolon because this is a statement.
So, we can read here as well, printf is a function which causes the message Hello World.
So, when we will see on our output screen, we will be able to see Hello World is getting displayed over there.
So, we understood all these four lines that what they are doing and in which way they are working.
Now we will come to the next line and see what it does.
Return 0 is basically, our main function or main door which was there, we have to close it now.
So, our return 0 line is telling us that.
So, we had taken an example of a house, where there is a main door, you have entered the main door, you keep on walking, there will be some wall which will tell you that now the house has ended.
There is no house beyond this wall, beyond this there is someone else's house.
This return 0 line that you are able to see, this works in the same way the way the wall is telling you that here your house has ended.
So, from where was our main function started, from where main is written and where did it end? To return 0.
Whenever we will see the return 0, you should be able to understand that your main function has ended.
So, all these things that were there, the parts of our code’s example, we have understood one by one that what is the work they are doing? How are they being used? And after that, at the end this curly bracket that you're seeing, you must have already understood that we had started the main function with the curly brackets so the end also will have to be done with curly brackets.
So, in this way, we have used the opening and curly brackets.
After this, we have understood what should be the flow of our program, how will it start and after that, how will it end.
Now we have to see how it will get compiled.
Let's see how this will get compiled.
Since we are going to use the Visual Studio Code as a text editor.
There we will type our program and after saving that program, which means there will be a save option that will come.
I will show it to you by going to the Visual Studio Code.
A save option will come there, you have to save and then you have to take the cursor on the screen and right click.
After right clicking you will get these options, which you're seeing right now on the screen.
You have to go on the run code option.
As soon as you click on the run code option.
Your compiler will start and will start reading your lines one by one and it will try to understand what you are trying to say with the help of your program.
After reading the lines and after completing all the work, it will give you all the desired action output on your screen.
How does it work? Let's go and see in our Visual Studio Code.
This is our Visual Studio code, we have already written the Hello World program where we have written “#include, stdio.h”, after that our int main function has started and then there was printf line, inside whatever was written, we had to print that.
Then there is return 0.
What is the return 0 telling us? It is telling us that our main function is ending over here.
I will do it again once and show it to you how I made this file.
You must be seeing this Visual Studio Code, all its options you can explore.
The option that we have to use currently, that would be the file one.
After going into the file, we have to click on new file and the new file will be created here.
You can even do it in this way.
First of all, you have to open a folder, so you will go into the file and you will see a fifth option here of opening the folder.
So, you will click on it, since I have to currently work on my desktop, so I will select the desktop and I will select the folder.
As soon as I selected the desktop you can see that my desktop folder will open in this.
Currently there is nothing on my desktop, that is the reason you can see blank here.
Whichever files would be there on your desktop, those you will see below.
Now what do you have to do? You can see the desktop folder over here.
After that, you will see a new file option over here.
You have to left click on it and you have to give some name to your file.
Like, since we're making a hello world program, I would name it “Hello World”.
After that, you have to put a dot and write C.
Here you can see I have written “helloworld.c”.
Why I have written .c because we know that we are learning C programming language, so it's a file extension that is there, the name that we have to write in front of the file, that is .c.
Otherwise when we make a Word file, it’s extension is doc or if we make a pdf, its extension is pdf.
In the same way, extension of C program is .c.
After writing this we will press enter, within a few seconds you will see that your helloword.c file will open here and you can see that the cursor is blinking here and saying that type your C program over here.
Without any delay we will quickly type here what we had learned and what we saw right now, our Hello World program.
We will quickly type it over here, first of all we have written a preprocessor command over here, after that our main door, which is the main function that we have written and to have a start and end to the main function, we have given the curly brackets.
After that currently there is no need to add the comment here.
Because we know that we are making a C program over here of Hello World.
So that's the reason why we don't require it.
We will write here printf after that we will put brackets over here, double quotes will come here and we will mention here that this is a Hello World program.
That is the reason why we are writing hello world over here.
After that, we will put a semicolon which will tell us that this statement has ended.
Since we have to close the main function, what we will write here is return 0 and semicolon.
So, our entire C program is done, this is complete.
The Hello World C program is complete.
You can see a white dot over here.
Which means that your program is not saved.
So, if you go here inside the file and click on the Save option.
You can even use the shortcut.
If you click on save, your program will be saved.
What do you have to do now is you have to go anywhere on the screen and right click.
Like I had told you, all these options will be displayed over here.
You have to go on the first option and you have to click on run code.
As soon as you click on the run code, you will see that there is a box-like thing open below.
This is our one output screen.
Okay.
On this output screen we can see that the compiler has compiled our code and told it to the computer how to do what and our computer has printed the statement over here.
Like everyone can see.
The way you had defined that you have to get Hello World written.
Exactly the same Hello World is displayed over here.
This power, this functionality of a C programming language, this makes it more efficient, structured and better.
So, we explored the first program of the C programming language here.
We will learn more things going ahead and understand them and even make big programs.
Whose functionality will be better than this.
If you feel that there is any part of this topic or this video that you may not have understood, based on that topic, any question or query you can ask us without any inhibition.
You have to go on forums.learnvern.com You have to type out your query there in your language, we will come to you with the solution or the answer as soon as possible in your own language.
Apart from this if you want to have a discussion on any of the topics, even that you can do on forums.learnvern.com.
After this we are going to learn a few basic syntax which we use in C language.
What is the syntax? Syntax means the way of writing the C programming language, all these things we are going to learn in the coming up topic.
Till next time, thank you so much everyone.
Share a personalized message with your friends.