Home » C programming language

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

Ad: Are you a blogger? Join our Blogging forum.



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.