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

  • A+
Category:Languages

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.

 


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.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: