The #operator is called stringizing operator. It allows a formal
argument within a macro definition to be converted to a string. If a formal
argument in a macro definition is preceded by this operator, the corresponding
actual argument will automatically be enclosed in double quotes.
Consecutive
whitespace characters inside the actual argument will be replaced by a single
blank space, and any special characters, such as ‘ , “ and \, will be
replaced by their corresponding escape sequences; e.g., \ ‘ , \ “ and
\ \. In addition, the resulting string will automatically be concatenated
(i.e., combined) with any adjacent strings.
Ex:
#include<stdio.h>
#define sum(xy) printf(#xy “=%d\n”,xy)
void main()
{
……………………
………………………
sum(a+b);
……………………
………………….
}
Here printf(#xy
“=%d\n”,xy) is equal to the printf(“a+b
=%d\n”,a+b);
No comments:
Post a Comment