ในโปรแกรมนี้เราจะดูว่า macros ใช้ concatenate สอง strings ยังไง สร้างสตริงสองตัวขึ้นไปใน macro แล้วเขียนต่อกันเพื่อรวมเป็น concatenated string syntax เหมือนด้านล่าง:
#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
ตัวอย่างโค้ด
#include<stdio.h> #define STR1 "Hello" #define STR2 "World" #define STR3 STR1 STR2 main() { printf("%s", STR3); }Output:
HelloWorld