# 和 ## 的区别
生活随笔
收集整理的這篇文章主要介紹了
# 和 ## 的区别
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
參考:# 和 ## 的區別
作者:枕上
發布時間:2021-07-25 08:23:40
網址:https://blog.csdn.net/jinchi_boke/article/details/119076280?utm_source=app&app_version=4.11.0&code=app_1562916241&uLinkId=usr1mkqgl919blen
#:
1、最常見的是 #不會替換參數,只替換其所對應的字符
2、 把宏參數變成一個字符串;
##:
把兩個宏參數連接到一起(只能兩個)
Demo:
#include <stdio.h> #include <stdlib.h>#define ONE 1 //1.最常見的是 #不會替換參數,只替換其所對應的字符; #define toString(str) #str //2.轉字符串 #define hehe(x,y) x##y //連接int main() {printf("%d\n",ONE); //#不會替換參數,只替換其所對應的字符;printf(toString(123456)); //輸出字符串"123456"printf("\n %d \n",hehe(1,2)); //輸出 int 12char string[]="hello world!"; puts(hehe(str,ing)); printf("%s\n",hehe(str,ing));system("pause");return 0; }輸出結果:
1 12345612 hello world! hello world!總結
以上是生活随笔為你收集整理的# 和 ## 的区别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: wemosD1_WIFI模块 与 ard
- 下一篇: 回溯法 -数据结构与算法