- The 2 operators used in the preprocessor are
- If the macros are present with in the quoted strings it is not replaced by the #defined macro.
- But if the macroname is preceded by a # then the macro is expanded into a quoted string with the parameter replaced by the actual argument
#define toprint(expr) printf(#expr "=%d\n",expr)
when toprint(x/y);is invoked the macro is expanded in to
and the strings are concatenated.so the statement becomes
The output of the above program is x/y=2
- In the above example instead of #expr if only expr is present like
#define toprint(expr) printf("expr=%d\n",expr) then the output is expr=2
- The preprocessor operator ## provides a way to concatenate actual arguments during macro expansion.
- If a parameter in the repacement text is adjacent to a ##, the parameter is replaced by the actual argument,the ## and surrounding white space are removed,and the result is rescanned
- Example The macro Join concatenates its two arguments
#define Join(front,back) front##back
now Join(hello,100) resuts hello100.
- A preprocessor line of the form # has no effect
- if the line has only #symbol the preprocessor ignores the line