Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does // in a string does not start a comment in C++?

I am printing a line like this

cout<<"Hello //stackoverflow";

And this produces the following output

Hello //stackoverflow

I want to know why it does not give me an error as I commented half of the statement and there should be

missing terminating " character

error.

like image 668
Nishant Chaudhary Avatar asked Jul 18 '18 15:07

Nishant Chaudhary


1 Answers

The grammar of C++ (like most of programming languages) is context-sensitive. Simply, // does not start a comment if it is within a string literal.

like image 109
eerorika Avatar answered Nov 10 '22 10:11

eerorika