Hi this is Anil from learning Lad and welcome to another video tutorial on the C programming
language
now in the previous videos we have learnt about the computers and the C programming
language and in this video we are going to see all the steps involved from writing a
C program to generating an executable file from that C program.
the first thing is C is a general purpose programming language and by using the C programming
language, we can write the instructions or the computer programs.
Now the instructions written in any programming language in human readable format is called
as the source code and here the instructions written in the C programming language is called
as the C source code
now when we write a computer program, we are going to store that in the Computer memory
as the computer file and the file which is containing this source code is called as the
source file and if the file is containing the source code written in the C programming
language then that file is also called as the C source file.
now as I said before we are going to write the instruction using the C programming language
and then we are going to save that in the Computer memory.
so to write the instructions or to write the code we are going to use the text editors.
you can use any text editor available and you can write the C program and you can save
that as a computer file.
now while writing in the C programming language this C programming language it provides a
lot of built-in features to implement the common operations that we have to do in the
program.
for example in programming, someone has to frequently perform the input and output operations
or programmers have to work on the string values.
so for all this common operations the C programming language provides the built-in features.
so the programmer can just use that built-in features and then he can write the programs
and these features are provided in the form of C standard library.
This C standard library contains all the built-in features that will perform the common operations
that a programmer have to perform in his program. so while writing the C program you are going
to use that built in features and then you will write the program and we will talk more
about this when we write the program and just now remember that C programming language provides
a lot of built-in features that we can use in our program and we can easily write the
programs.
And the next thing is as I said before we are going to write the C program using a text
editor and then we are going to save that in the Computer memory as a computer File.
so the next thing is how we can differentiate a file which is containing the C programming
language from any other file. for example if we have a text file then that text file will
have .TXT extension. so by looking at this .TXT extension we can say that that file is
a text file. similarly for the music files which have the
MP3 format will have .MP3 extensions and similarly the PDF files have .PDF extension.
so similar to all these files, the file which is containing the c source code will be saved
with dot C extension. so here you can give any name to your file
while saving it but you have to make sure that it has the extension dot C.
for example if I write a program using C programming language by using a text editor and then while
saving that file I can give any name. for example I can name it one. but it should have
the extension dot C. so my file has to be saved as one.c
This .C will indicate that it is a file containing the program written in the C programming language.
and now the next thing is once we write the C program using the C language you know we can’t directly
execute that code in a computer. That’s because the computers they can only
understand the code which is written in the binary language or the machine code. and that's
why we need to convert the source code that we have written in the C language to machine
code and we can do that by performing the compilation process.
so we will perform the compilation process and we will convert this code to the machine
code and that machine code generated by this compilation process is also called as the
object code.
This compilation process, it will take the source code written in the C programming language
and then it will generate a new file containing the machine code representation of the source
code.
and now here the file containing this object code is also called as the object file and
if you are performing this compilation process in the windows environment then this object
file containing the object code will have .OBJ Extension and if you are performing this
in the Linux or Unix environment then this object file containing the object code will
have .O extension.
now here during this compilation process several programs are used.
One of the program which is used in the compilation process is the preprocessor.
here before the actual compilation process, your Source code written in the C programming
language will be processed and as the name indicates this preprocessor is a program,
it takes the source code and then it will perform some operations on it.
for example it will remove the new lines and spaces that you have in the source code and
also it will remove the comments and also it will expand the header files.
I know all of you guys can't understand this header files and comments. you will I know
learn about that later but just remember that this is preprocessor is a program which is
called during the first stage of this compilation process and it will process this source code
and then it will generate an optimised version of the source code and then that optimised
version of the source code produced by this preprocessor will be given to the compiler.
and here since we are talking about the C programming language it is gonna be a c compiler
and this c compiler will generate the machine code from the source code given to it.
so here there are different C compilers are available and although they perform the same
thing, converting the source code written in C language to the machine code, they work
a bit differently some of the compilers they take the source code and then they generate
the Assembly code and then that assembly code has to be converted to machine code. and some
C compilers they directly generate the machine code from the source code given to them.
so here to programs are mainly used and the first one is the preprocessor.
this preprocessor will take the source code written in the C programming language and
then it will produce the optimised form of the source code and then that optimised source
code which is produced by this preprocessor is given to this c compiler and then this
C compiler will generate the machine code which is also called as the object code.
now here what you can do is you can divide your program in separate files.
for example let's say you are writing a project using the C programming language and your
project contains more than 10000 lines of C programming language instructions.
so at that time if you have that more than 10000 lines of code in just one single file
then it will be difficult for you to manage your project.
instead of that if you can do at that project into several different parts and also into
several different files then it will be easy for you to manage the code.
so while writing the programs in the C programming language you can divide your project into
several different files. for example I can have different files here. for example one.c
then two.c and then three.c
I can have any number of files which is containing the C source code.
now here if your project contains more than one file containing your programs then you
have to individually compile each of them and generate the object code.
so you have to perform the compilation process on this one.c and then you have to generate
the object code for this one.c and then for this two.c also you have to do the same thing
and for this three.c also you have to do the same thing.
so for each file which you have in your project, you have to perform the compilation process
and you have to generate the object code for that respected source files.
so now here and I’m gonna assume that my project that I'm building has three files
containing the instructions written in the C programming language.
so one.c two.c and three.c so I have to perform this compilation process
on each of them and I have to generate the object code for each of them.
So here after the compilation process I have the object code of these three files.
so let's say one.OBJ and two.OBJ and three.OBJ
All Right. now this object file is generated after this
compilation process. Now here during this compilation process the
compilers may detect some errors in your programs. so at that time the compilers will generate
the errors instead of creating the object file.
so if your program is containing the errors then the compilers will generate error and
you have to go back to your source code and you have to solve those errors.
so if your program contains errors then this compilation process will detect that then
you have to go back to your source code and you have to correct the error and after correcting
the errors you have to again perform this compilation process and at that time if your
program is not containing any error then the object code will be generated.
so once you get your programs error free then the object Files will be generated.
now the next thing is now we have the object files which is containing the machine code
for our project.
now that we have to do is we have to link all these files together and we have to generate
an executable. And for that purpose a program is used and
it is called as the linker. and this linker, it will take the object files,
all of them and then it links them together and then it generates the executable file
and in the windows environment this executable will have the .EXE Extension and similarly
for the different platforms they have their respected the executive extension.
And here it takes the object files and also I have said before while writing the C program
you are going to use the features provided by the C language and that features are provided
in the C standard library. so this linker will link the features that
you have used from the C standard library with your code and then it will produce the
executable. so if your project is containing only one
file then it will take that one file and then if you have used any library functions in
your program then it links them together and produces the executable.
And similarly let's say your project is containing 3 files and then after the compilation process
you will get the three object files and this linker will take that 3 object files and also
it links them together and also it links the standard library functions that you have
used and then it produces the executable.
now we have this executable file which can be executed in a computer.
now during this linking process also the linker may find out that your program is containing
some errors. for example let's say you have made some mistakes
while including or while using the features provided in the standard library.
so at that time the linker will generate the error saying that it can't link the files.
so again you have to go back to your source code and you have to find the error that you
have made in your source code and then you have to correct that.
And after correcting that you have to perform all the steps again. you have to compile them
and then we have to link them. if there are no errors then the linker will
successfully create the executable.
now that thing that we have to do once we get an executable is, we have to execute that
program and for that purpose a program is used and that is called as the loader.
this loader will take your executable and it will load that to the primary memory which
is the RAM stand for Random Access Memory and then the processor will execute it.
And here after executing your program, your program May work or may produce the result
successfully or it may not work properly. for example let's say you have written a program
to calculate the area of a triangle and in your source code lets say you have done a
mistake while writing the formula to calculate the area of the triangle.
so that's why you will not get any error because the computer doesn't know the formula to calculate
the area of a triangle. you have to provide that correctly. but you
have done the mistake In that. that's why you will get to this execution
stage but your program it will not produce the proper results.
it will generate improper results. and that's why if your output after executing
your program is not proper then also you have to go back to your source code and you have
to correct your program.
And then you have to perform all these operations again, and then you have to execute your program.
so this is the steps involved from writing a C program and then creating an executable
and then executing that executables generated. Now the thing is all these programs which
are required to generate the executable from the C program source file, they come in a
bundle.
so you have to install a bundle which contains all these software's and that bundle is called as
the tool set. so once you install a tool set for the C programming
language, you will get all these softwares. you won't get the editor you can write it
in any text editor but you will get all these programs for example to perform the compilation
process and for this linking purpose and all those softwares will be available in this
tool set.
There are many tool sets available for example we have the GCC tool set and we have Turbo
C and also we have the Microsoft specific visual C++.
You know all these tool sets are available they provide all these programs.
so you just need to install the toolset, and then you will get all these programs then
you can build and execute your program.
so this is it guys, this is all about the steps involved from writing a C program to
generating an executable from it and then executing that generated executable file.
and if you like this video then give a thumbs up if you don't like it then give a thumbs
down and also tell your opinion by writing the comments in the comment section and also
if you think that this video will help any of your friends then do share this video with
them and also if you want to watch more tutorials like this, then subscribe to my channel learning
lad and once again thank you for watching and I'll see you next tutorial.