- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Algorithm
Step 1:Take two strings Step 2: Use macro to concatenate the strings Step 3: End
Example Code
#include<stdio.h> #define STR1 "Hello" #define STR2 "World" #define STR3 STR1 STR2 main() { printf("%s", STR3); }
Output:
HelloWorld
Advertisements