用於字串連線的 C/C++ 宏


在本程式中,我們將看到如何使用宏連線兩個字串。我們可以在宏中建立兩個或兩個以上的字串,然後將它們一個接一個地寫入,以將它們轉換為連線字串。語法如下所示

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

輸入:輸入兩個字串

輸出:返回連線後的字串。

演算法

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);
}

輸出

HelloWorld

更新於: 30-Jul-2019

4K+ 瀏覽量

開啟您 職業生涯

完成課程便可獲得認證

立即開始
廣告
© . All rights reserved.