It helps if you tell us what syntax error you're getting.
You define macro pr as not having any parameters, but then you try to pass it a parameter when you call it.
- There can't be any spaces between the macro name and the open-parenthesis in the macro definition if you wish to define a macro that takes arguments.
- A macro is not a function, you don't specify the types of the macro arguments in the macro definition.
If we make those corrections to your code we get this:
- #define pr(n) printf("%d",n);
-
void main(void)
-
{
-
int f;
-
scanf("%d",&f);
-
pr(f);
-
}
Which after macro substitution turns into this:
- void main(void)
-
{
-
int f;
-
scanf("%d",&f);
-
printf("%d",f);;
-
}
Note the two semicolons on line 5. The first comes from the macro expansion, the second comes from your original source.
Consider what would happen here:
- #define pr(n) printf("%d",n);
-
...
-
if (flag)
-
pr(f);
-
else
-
pr(g);
After macro substitution you get:
- if (flag)
-
printf("%d",f);;
-
else
-
printf("%d",g);;
which is logically equivalent to
- if (flag)
-
printf("%d",f);
-
;
-
else
-
printf("%d",g);
-
;
It is considered bad form to include a command-terminating semicolon in a macro definition.