
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Stringize and Token-pasting operator in C
In this article we will see what are the Stringize operator and Token Pasting operator in C. The stringize operator (#) and the token pasting operator (##) are preprocessor operators used within macros for text manipulation. It sends commands to compiler to convert a token into string.
Stringize Operator (#)
The stringize operator (#) is a preprocessor operator that converts the micros parameter into a string literal. The preprocessor encloses the actual argument passed to the macro in double quotes, effectively convert it into a string.
Syntax
Following is the syntax of Stringize Operator:
#define MACRO_NAME(arg) #arg
Example
In the following example, we demonstrate the use of the Stringize Operator in C:
#include <stdio.h> #define STRINGIZE(x) #x int main() { printf("%s\n", STRINGIZE(tutorialspoint India)); printf("%s\n", STRINGIZE(12345)); return 0; }
Following is the output:
tutorialspoint India 12345
Token Pasting Operator (##)
The token pasting operator (##) concatenates two tokens into a single token. When the token pasting operator(##) appears b/w two tokens within the macro, the preprocessor combines them to form a new token.
The Token Pasting operator is a preprocessor operator. It sends commands to compiler to add or concatenate two tokens into one string. We use this operator at the macro definition.
Syntax
Following is the syntax of Token pasting Operator:
#define MACRO_NAME(arg1, arg2) arg1 ## arg2
Example
In the following example, we demonstrate the use of the Token Pasting Operator in C:
#include <stdio.h> #define concat(a, b) a##b int main(void) { int xy = 2050; printf("%d", concat(x, y)); return 0; }
Following is the output:
2050