×

C Tutorial

C Basics

C Data Types

C Input/Output

C Operators

C Conditional Statements

C Control Statements

C Strings

C Functions

C Arrays

C Structure and Unions

C Pointers

C Preprocessor Directives

C Command-line Arguments

C File Handlings

C Graphics

C Advance Topics

C Tips and Tricks

C Important Topics

C Practice

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.