Hash and Hash# Operators in C



In this section we will see what are the Stringize operator(#) and Token Pasting operator(##) in C. The Stringize operator is a preprocessor operator. It sends commands to compiler to convert a token into string. We use this operator at the macro definition.

Using stringize operator we can convert some text into string without using any quotes.

Example

 Live Demo

#include<stdio.h>
#define STR_PRINT(x) #x
main() {
   printf(STR_PRINT(This is a string without double quotes));
}

Output

This is a string without double quotes

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.

Example

 Live Demo

#include<stdio.h>
#define STR_CONCAT(x, y) x##y
main() {
   printf("%d", STR_CONCAT(20, 50));
}

Output

2050
Updated on: 2019-07-30T22:30:26+05:30

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements