使用 C 語言列印一個字串而不使用任何引號


這是另一個棘手的問題。在此程式中,我們將看到如何在 C 中使用沒有引號的字串進行列印。

此處我們使用宏函式。我們正在定義宏函式,如下所示

#define getString(x) #x

getString() 是一個宏函式。它透過將 x 轉換為字串來返回 x。x 前面的 # 表示該函式將 x 轉換為字串。

Input: Take one string without quote
Output: Print that string into console

演算法

Step 1:Take a string without quote
Step 2: Use macro function to print it into a string
Step 3: End

示例程式碼

 線上演示

#include<stdio.h>
#define getString(x) #x
//The # will convert x into a string
main() {
   printf(getString(Hello World));
}

輸出

Hello World

更新於: 2019-07-30

680 瀏覽量

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.