[noob][c++] comments

how many ways are there in comment in the c++ language?

I know   //

are there any others?
Who is Participating?
UrosVidojevicConnect With a Mentor Commented:
- The /* (slash, asterisk) characters, followed by any sequence of characters (including new lines), followed by the */ characters. This syntax is the same as ANSI C.

- The // (two slashes) characters, followed by any sequence of characters. A new line not immediately preceded by a backslash terminates this form of comment. Therefore, it is commonly called a "single-line comment."


evilrixConnect With a Mentor Senior Software Engineer (Avast)Commented:
See below...
// This is C++ style commenting and is preferred
** This is C style commenting but it not often used in C++
** as it can cause problems with nested comments
** /* like this which will not compile */  so prefer to use C++
** style unless your code really is C only

Open in new window

Infinity08Connect With a Mentor Commented:
Wow, I'm impressed by the syntax checks in the code snippets !!

Technically, the following is not called "commenting", but it does make part of the code invisible to the compiler :

#if 0

Open in new window

Infinity08Connect With a Mentor Commented:
Note that the #if 0 technique is an easy way to hide blocks of code without suffering from the nested comments problem evilrix mentioned. You just change #if 0 to #if 1 if you want to enable the block again :)
Deepu AbrahamConnect With a Mentor R & D Engineering ManagerCommented:
There are only 2 ways of commenting in c++ as mentioned above. However the preprocessor tells the compiler to ignore or include certain blocks which is more or less similar to commenting when you look at compiler point of view

//some code

This will get compiled only if you define MY_DEBUG in preporcessor or like
 #define MY_DEBUG

Best Regards,
All Courses

From novice to tech pro — start learning today.