(5) What is use of # and ## operator in c program ?
Ans:
There are two operator in preprocessor.
1. # this operator is called stringizing operator which convert any argument in the macro function in the string. So we can say pound sign # is string maker.
e.g
#define string(s) #s
void main()
{
char str[15]=string(World is our ) ;
printf(“%s”,str);
}
Output: World is our
Explanation : Its intermediate file is :
Argument of string macro function ‘World is our’ is converted into string by the operator # .Now the string constant “World is our” is replaced the macro call function in line number 4.
2. ##
This operator is called token pasting operator. When we use a macro function with various argument then we can merge the argument with the help of ## operator.
e.g
#define merge(p,q,r) p##q##r
Void main()
{
int merge(a,b,c)=45;
printf(“%d”,abc);
}
Output : 45
Explanation :
Arguments a,b,c in merge macro call function is merged in abc by ## operator .So in the intermediate file declaration statement is converted as :
int abc=45; |