Token Pasting Directive Operator (##) in C - Token Pasting Operator in C
Learn C - C tutorial - token pasting directive operator in c - C examples - C programs
Token Pasting Directive Operator (##) in C
- Token pasting operator just eliminates white space around it and combines the non-whitespace characters.
- It is used to create new tokens & can only be used in a macro definition.
Sample Code
#include <stdio.h>
#define CONCAT(x,y) x##y
int main()
{
printf("Value1: %d\n",CONCAT(10,20));
printf("Value2: %d\n",CONCAT(10,45)+100);
return 0;
}
Output
Value1: 1020
Value2: 1145
- Here, statement CONCAT(10,20) will return 1020 as integer and statement CONCAT(10,45)+100 will concatenate 10, 45 and then add 100 to the 1045, so this statement will return 1145 as integer.