C/C++ 中的行拼接


在本節中,我們將瞭解 C 或 C++ 中的行間距。有時我們使用雙斜槓“//”來新增一些單行註釋。單行註釋基本上在轉到下一行時結束。但是,如果我們在一些單行註釋的末尾加上反斜槓,那麼會產生什麼影響?

當使用反斜槓時,它將繼續到下一行。因此,在註釋行之後,如果註釋後面有幾行,也會被忽略。讓我們來看一個例子。

示例

 即時演示

#include <iostream>
using namespace std;
int main () {
   //This is a comment line ending with back slash\
   cout << "Line after comment" << endl;
   cout << "Next line";
}

輸出

Next line

在這種情況下,我們必須在註釋行和下一行程式碼之間留一行額外的空白。請檢視之前的程式碼和下一段程式碼之間的差異。

示例

 即時演示

#include <iostream>
using namespace std;
int main () {
   //This is a comment line ending with back slash\
   cout << "Line after comment" << endl;
   cout << "Next line";
}

輸出

Line after comment
Next line

更新時間: 30-Jul-2019

452 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始行動
廣告
© . All rights reserved.