ในส่วนนี้เราจะดู line splicing ใน C หรือ C++ บางครั้งเราใส่ single line comment ด้วย double slash “//” one-line comment จบเมื่อขึ้นบรรทัดใหม่ แต่ถ้าใส่ back slash ท้าย comment line จะเกิดอะไรขึ้น?
เมื่อใช้ back slash จะต่อไปบรรทัดถัดไป ดังนั้นหลัง comment line หากมีโค้ดต่อจะถูก ignore ด้วย ดูตัวอย่าง:
ตัวอย่าง
#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
ในสถานการณ์นี้ต้องเว้นบรรทัดว่างระหว่าง comment และโค้ดถัดไป ดูความต่าง:
ตัวอย่าง
#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