Sunday 19 August 2012

c program stringizing operator (#) | stringizing operator (#) examples | comments

/* 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);

}
Share This
Previous Post
Next Post

FYJC XI standard online admisson Process and declaraton of Merit list . Cut off List For prevous year also . 10 Th Results onlne declaraton Maharashtra Region .

0 comments: