C 中的 # 和 ## 運算子?
在本節中,我們將介紹 C 中的字串化運算子 (#) 和標記貼上運算子 (##)。字串化運算子是一個預處理器運算子。它向編譯器傳送命令,將標記轉換為字串。我們在宏定義中使用此運算子。
使用字串化運算子,我們可以將某些文字轉換為字串而不使用任何引號。
示例
#include<stdio.h>
#define STR_PRINT(x) #x
main() {
printf(STR_PRINT(This is a string without double quotes));
}輸出
This is a string without double quotes
標記貼上運算子是一個預處理器運算子。它向編譯器傳送命令,將兩個標記新增到一個字串中或將其連線在一起。我們在宏定義中使用此運算子。
示例
#include<stdio.h>
#define STR_CONCAT(x, y) x##y
main() {
printf("%d", STR_CONCAT(20, 50));
}輸出
2050
廣告
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP