-
Junior Member
preprocessor
#define a 10
main()
{
printf("%d..",a);
foo();
printf("%d",a);
}
void foo()
{
#undef a
#define a 50
}
The output is 10..10 how it will come
-
Contributing Member
Re: preprocessor
Hi,
The preprocessor is invoked by the compiler as the first phase in the translation process. The preprocessor replaces all occurrences of the macro with the value. In the above program the second definition of a is after the second printf(). Hence the O/P is 10..10
-
Junior Member
Re: preprocessor
But this one dispaly 50..50
#define a 10
foo()
{
#undef a
#define a 50
}
main()
{
printf("%d..",a);
foo();
printf("%d",a);
}
-
Contributing Member
Re: preprocessor
#define a 10
print() {
printf("%d..",a);
}
foo()
{
#undef a
#define a 50
}
main()
{
printf("%d..",a);
foo();
printf("%d",a);
print();
}
Check this out. This will make it clear.
(The o/p should be 10..50..50)
--Smile, it makes people wonder what you are thinking.
-
Junior Member
Re: preprocessor
hi... I need a explanation for this..
#define f(g,g2) g##g2
main()
{
int var12=100;
printf("%d",f(var,12));
}
the output is 100
-
Contributing Member
Re: preprocessor
The very first thing that a C compiler does is:
It invokes the preprocessor. The function of the preprocessor is to replace all preprocessor directives with their appropriate substitution.
Consider the program that you have:
#define f(g,g2) g##g2
main()
{
int var12=100;
printf("%d",f(var,12));
}
In this program ## means concat the two variables passed to this function. This is called Token Concatenation.
The preprocessor will replace this with:
main()
{
int var12=100;
printf("%d", var12);
}
Go through the following links:
en . wikipedia . org/wiki/C_preprocessor
www . cs . utah.edu/dept/old/texinfo/cpp/cpp . html
--Smile, it makes people wonder what you are thinking.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules