C/C++ Macro for string concatenation

In this program we will see how the macros are used to concatenate two strings. We can create two or more than two strings in macro, then simply write them one after another to convert them into a concatenated string. The syntax is like below:

#define STR1 "str1"
#define STR2 " str2"
#define STR3 STR1 STR2 //it will concatenate str1 and str2

Input: Take two strings

Output: Return concatenated string.


Step 1:Take two strings
Step 2: Use macro to concatenate the strings
Step 3: End

Example Code

 Live Demo

#define STR1 "Hello"
#define STR2 "World"
#define STR3 STR1 STR2
main() {
   printf("%s", STR3);



Updated on: 30-Jul-2019

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started