Stringizing operator (#)
The stringizing operator (#) is a preprocessor operator that causes the corresponding actual argument to be enclosed in double quotation marks. The # operator, which is generally called the stringize operator, turns the argument it precedes into a quoted string. It is also known as the stringification operator.
It is generally used with macros in C.
Example
The following C code demonstrates the usage of the Stringizing operator (#).
C
#include <stdio.h>
#define mkstr(s) #s
int main( void )
{
printf (mkstr(geeksforgeeks));
return 0;
}
|
Explanation
The following preprocessor turns the line printf(mkstr(geeksforgeeks)); into printf(“geeksforgeeks”);
Token-pasting operator (##)
The Token-pasting operator (##) allows tokens used as actual arguments to be concatenated to form other tokens. It is often useful to merge two tokens into one while expanding macros. This is called token pasting or token concatenation.
The ‘##’ pre-processing operator performs token pasting. When a macro is expanded, the two tokens on either side of each ‘##’ operator are combined into a single token, which then replaces the ‘##’ and the two original tokens in the macro expansion.
Examples
The following C code demonstrates the usage of the Token-pasting operator (##).
C
#include <stdio.h>
#define concat(a, b) a##b
int main( void )
{
int xy = 30;
printf ( "%d" , concat(x, y));
return 0;
}
|
Explanation
The preprocessor transforms printf(“%d”, concat(x, y)); into printf(“%d”, xy);
Application of Token-pasting operator (##)
The ## provides a way to concatenate actual arguments during macro expansion. If a parameter in the replacement text is adjacent to a ##, the parameter is replaced by the actual argument, the ## and surrounding white space are removed, and the result is re-scanned.
If you like GeeksforGeeks and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks. Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
07 Aug, 2023
Like Article
Save Article