Hi this Is Anil from LearningLad and welcome to the guess the output video series on C
programming language.
In this video I have a C program in the screen.
All you have to do is pause this video and take a look at the source code and then first
you need to find whether this program contains an errors.
if you think this program is error free then you need to guess the output of the program.
once you have an answer for this program, you can play the video.
I am going to run the program and explain whatever the output will come.
Now you guys can pause this video.
AlI right.
now I think you guys have an answer for this program, I am going to build and run this.
so I'm going to do build and run and the output that we get for this program is “welcome
to Learning Lad”
so now why we get the output like this?
Here if you look at the source code first we have defined a macro called youtube and
the definition of this macro youtube is main and then we have a printf statement inside
this function which will display “welcome to LearningLad”
so here all of you know that in a C program we should have one main function.
now if you look at source code here then we don't have a main function but still our program
runs.
so why this program runs?
now before the actual compilation process there is a step called as the “Pre Processing”
and during the pre processing the preprocessor program will search for the macros used in
the program and it will replace those macros with that macros definition.
So here the preprocessor will search for youtube in this code and then it will replace that
with main.
so the output of the preprocessor will contain this main function because it will replace
this youtube with main and then that output of the preprocessor is passed on to the compiler
for the compilation process and during that time this code has a main function and we
haven't made any mistake in the code and that's why you know we get the output “Welcome
to LearningLad”
now if you want to check the output of the preprocessor then you can do that.
For that first you have to open the folder where you have saved this program.
To demonstrate that I am going to open the folder where I have stored this a program
and here as you guys can see I have stored this program inside the what is the output
folder which is inside C programming folder which is inside the source codes folder which
is in the D drive.
so to check the output of the preprocessor I need to open up the command prompt in this
location.
so I can open the command prompt by going to the URL bar and just by typing the CMD
here and if I hit the enter button you guys can see we have the command prompt which is
inside this folder.
so now here what I can do as I can write a command.
The command is GCC and then we use -E to only preprocessor code you know it will not compile
the code, it will just do the preprocessing.
Then we need to leave a space and then we need to write the file name where we have
the source code.
This source code is inside this main.c file.
So i’m gonna specify that here.
Main.c
and if I hit the enter button it will you know display a lot of things.
these are the things the preprocessor has done.
first it has included the STDIO.h header files contents to our file and then in the end you
guys can see our main function.
Here we don't have youtube. we have main function or you know youtube
has been replaced with the main.
so this is the work of the preprocessor and when this code is compiled, we have a main
function and all other things are proper and that’s why this program runs and we get
the output as “welcome to LearningLad”
So this is it guys for this video.
Thank you for watching.
If you feel like this video hit the like button.
if don't like it it then hit the dislike button and if you want to say something then write
that in the comment box and if you think this video will help any of your friends then do
share this video with them.
thank you for watching I'll see you later in the next video.