Hi this is Anil from learningLad YouTube channel and welcome to the Guess the output video
series on C programming language.
now here in this screen, you guys can see a C program.
you need to pause this video and take a look at the source code and first you need to check
whether this program contains any error and if you think this program doesn't contain
any error then you need to guess the output of this program.
once you guys have an answer, play this video again.
I will run this program and explain the output.
Now you guys can pause this video.
All right.
now I guess you guys have an answer for this program.
I am going to build and run this program and we get the error at line number 6 and if I
open up the error logs it says error At The Line Number 6.
invalid preprocessor directive #check and then in the line number 8 it says error.
Endif preprocessor directive without a if preprocessor directive.
So Let's close this.
ok now let's see why we get this error here.
In this program we have defined a macro called as check with the value of if and then we
have defined another macro X with a value of 100.
And in this main function which we have used this check Macro here and then we are checking
whether this X macro is containing a value of 100.
If it is so that we are including this line for the compilation process and then you know
we have this printf function.
so here we are expecting this CHECK macro to expand to if and we are expecting it to
work like #if here.
But in C programming the # and the preprocessor directive name cannot come from a macro expansion.
There are rules to use the preprocessor directives.
so first we need to use the symbol hash and then we need to write the preprocessor directive
name and then according to that preprocessor directive name we will be writing the other
values.
so here the # and the preprocessor directive name can not come from a macro expansion.
So here in this program, we are expecting this CHECK to expand and we are expecting
it to become if.
But that will not happen.
The preprocessor will check whether this is a valid preprocessor directive or not.
since this is not a valid preprocessor directive it generate the error.
Ok
This is about the first error and then we have another error and that is the endif preprocessor
directive without the if preprocessor directive.
Since this will not expand to #if, if we use this endif then it will be without a if preprocessor
directive.
so it generates that 2nd error.
SO one thing to remember is in C programming if you are using the preprocessor directives
then the # and the preprocessor directive name cannot come from a macro expansion.
so that's it guys for this video.
If you like this video then hit the like button.
if you don't like it then hit the dislike like button.
if you want to say something then write that in a comment box.
if you wanna watch more tutorials like this then do subscribe and if you think this video
will help any of your friends then do share this video with them.
thank you for watching and I'll see you later in the next video.
Không có nhận xét nào:
Đăng nhận xét