[noob][c++] comments

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


I know   //


are there any others?
TroudeloupAsked:
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."

http://msdn2.microsoft.com/ja-jp/library/k1dbk8bw(VS.80).aspx
http://cplus.about.com/od/learning1/ss/clessonone_8.htm


0
 
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

0
 
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 :

    some_code_here();
#if 0
    this_code_is_hidden();
#endif
    and_we_resume_here();

Open in new window

0
 
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 :)
0
 
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

 #if MY_DEBUG
//some code
#endif

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

Best Regards,
DeepuAbrahamK
0
All Courses

From novice to tech pro — start learning today.