There are two operators in c 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. Example
#include<stdio.h>
#define string(s) #s
int main(){
char str[15]= string(World is our );
printf("%s",str);
return 0;
}
Output: World is our
Explanation : Its intermediate file will look like:
int main(){
char str[15]=”World is our”;
printf("%s",str);
return 0;
}
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. Example
#include<stdio.h>
#define merge(p,q,r) p##q##r
int main(){
int merge(a,b,c)=45;
printf("%d",abc);
return 0;
}
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;
3 comments:
Thanks
thanks a lot!!!
i don't understand the use of ## in merge what significance we get from it
Post a Comment