/* stringizing operator (#) * with output/
In a macro definition if the formal argument occurs inside a string in the macro expansion, then it is not replaced by the actual argument.
For e.g.
#define SHOW(val) printf(“val=%d”,val);
When SHOW(x) will be called, its expansion would be printf(“val=%d”,x);
To overcome this problem Stringizing Operator(#) is used.
The argument it precedes is converted into a string. Following program will make its usage clear.
/* C Program to learn the use of stringizing operator (#) */
#include
#define SHOW(var,format) printf(#var "= %" #format "\n",var);
int main()
{
int n=456;
float f=5.66;
char ch='$';
//calling stringizing operator for different datatypes and format
SHOW(n,d);
SHOW(f,0.2f);
SHOW(ch,c);
SHOW(n*f,0.2f);
}
In a macro definition if the formal argument occurs inside a string in the macro expansion, then it is not replaced by the actual argument.
For e.g.
#define SHOW(val) printf(“val=%d”,val);
When SHOW(x) will be called, its expansion would be printf(“val=%d”,x);
To overcome this problem Stringizing Operator(#) is used.
The argument it precedes is converted into a string. Following program will make its usage clear.
/* C Program to learn the use of stringizing operator (#) */
#include
#define SHOW(var,format) printf(#var "= %" #format "\n",var);
int main()
{
int n=456;
float f=5.66;
char ch='$';
//calling stringizing operator for different datatypes and format
SHOW(n,d);
SHOW(f,0.2f);
SHOW(ch,c);
SHOW(n*f,0.2f);
}
0 comments: