Token Pasting Directive Operator (##) in C

Operator ## is known as Token Pasting Directive Operator in C, which is used to concatenate Macro's arguments.

Defining Macro with ## Operator

#define macro_function(argument1, argument2)    argument1##argument2

Consider the following example

#include <stdio.h>

#define CONCAT(x,y) x##y

int main()
{
	printf("value1: %d\n",CONCAT(10,20));
	printf("value2: %d\n",CONCAT(10,20)+100);	
	return 0;
}

Output

value1: 1020
value2: 1120

Here, statement CONCAT(10,20) will return 1020 as integer and statement CONCAT(10,20)+100 will concatenate 10, 20 and then add 100 to the 1020, so this statement will return 1120 as integer.





Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.