HI this is anil with a video tutorial for the Learning Lad on c programming.
In this video tutorial we are gonna write our first ever program in c.
First go and open up your dev c++ compiler and go to file, new, source file.
So its gonna open up a blank file, Go to this File then save as and i am gonna save it in
my desktop and i am gonna name it first then make sure that it has the extension c source
files. So save it. So as you can see here you know
our first.c is ready to go. Before writing the statements in our program,
i just want to explain you about the functions. A function is a collection of statements to
do some particular task. So in every program we have to do some task
again and again. for example we have to print something to the screen, or to take the input
from the keyboard etc etc. So the code for all these task are grouped
into functions and they are stored in some files which are called header files.
To use that functions in our program, we just have to include that header files.
So in c we can include the header files by using a pre processor directive.
A pre processor is a software which processes our source code you know before the compilation.
So this pre processor provides some directives to include the files.
We are gonna use #include then, its a pre processor directive and we are gonna write
the file name . In this case we want to include a file which
contains the functions for printing something to the screen and taking the input from the
keyboard. So that file is called stdio.h
Here this stdio means that standard input output and .h is the extension for the header
file. Another file we are including is called conio.h
so i am gonna explain you why we are including this file later.
So when we encounter the statements. So next we have to write our main function.
So every c program begins with a main function. So we can say that you know a main function
is the entry point of your c program. If you won't write your main function then
your compiler is gonna give an error like ok i can't find the main function so i can't
execute your code. So its gonna be int main, then a pair of parenthesis,
then a pair of curly braces. So here this int means that our main function
is gonna return some integer value. Thats because you know every function can
return some values. So then this main is the name of the function.
So in every c program, we should have a main function.
Within this parenthesis if we want we can pass the parameters, you know thats the main
function can take. So now we are not passing any parameters.
Thats why we are leaving it blank. So with in this curly braces we have to write
the statements of this main function. Another thing i wanna tell you is you know
in c our statements will be executed one after other or in sequential order.
In this tutorial we just want to print some thing to the screen.
So for that purpose we can use a function provided by this stdio.h header file and that
function is called printf.
So with in this parenthesis in double quotes we have to specify the string we want to print
to the screen. So here i am gonna write hello learner.
So this is it then add a semi colon. This is important because you know every c
statement ends with a semi colon.
So if you forget to add a semicolon, you know after c statement then its gonna give you
an error.
So now as promised here that we are returning some integer value, we have to return it.
we are gonna use return keyword to return some value, then we are gonna write 0.
So now we are gonna save it compile it and run it.
So i don't think whether you guys have seen a you know a box just appeared and vanished.
So that means that our program has successfully executed from here to here and once our statements
ended or finished, you know our program terminated. So the execution speed is so fast that we
can't see the output. So if you want to see the output then we have
to add a pause in our program . So here you know after this printf statement
we want to add a pause so that you know whatever we have printed here, we can see that.
we can add a pause by using one of the method available from this conio.h header file and
that function is called getch() This getch function is not specifically made
for adding a pause. Actually by using this function we can receive
a character from your keyboard. But here when we use this function, you know
it makes the program to wait for some thing to be inputed from the keyboard.
So at that time you know we can see the output. So i am gonna save it, compile it and run
it. So as you can see we got this output hello
learner and you guys can see a blinking cursor here.
You know it just waiting for us to enter some key or enter some character from the keyboard.
so i am gonna press a key in my keyboard, you can press any key.
boom thats it. It just terminated our program.
So this is it, this is about the first program in c. so thank you for watching and don't
forget to subscribe, also like my facebook page at facebook.com/LearningLad
so i'll see you in the next tutorial.