#define a 10
main()
{
printf("%d..",a);
foo();
printf("%d",a);
}
void foo()
{
#undef a
#define a 50
}
The output is [SIZE="4"][B][U]10..10 [/U][/B][/SIZE]how it will come :confused:
Printable View
#define a 10
main()
{
printf("%d..",a);
foo();
printf("%d",a);
}
void foo()
{
#undef a
#define a 50
}
The output is [SIZE="4"][B][U]10..10 [/U][/B][/SIZE]how it will come :confused:
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 [B]a[/B] is after the second printf(). Hence the O/P is 10..10
But this one dispaly [B][I][U][COLOR="Blue"]50..50[/COLOR][/U][/I][/B]:confused:
#define a 10
foo()
{
#undef a
#define a 50
}
main()
{
printf("%d..",a);
foo();
printf("%d",a);
}
#define a 10
[B]print() {
printf("%d..",a);
}[/B]
foo()
{
#undef a
#define a 50
}
main()
{
printf("%d..",a);
foo();
printf("%d",a);
[B]print();[/B]
}
Check this out. This will make it clear.
(The o/p should be 10..50..50)
[SIZE=1]--Smile, it makes people wonder what you are thinking. :)[/SIZE]
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 [COLOR="Blue"]100[/COLOR]
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 [B]Token Concatenation.
[/B]
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
[SIZE=1]--Smile, it makes people wonder what you are thinking. :)[/SIZE]