Jakob Bieling wrote:
cdrsir <cd****@gmail.comwrote:
we can use
1) // my comments a
This type of comment will automatically end by the end of the line.
2) /* my comments b */
This one will end only when */ is found. This implies that you can
comment multiple lines using just /* and */ instead of having to start
each line with //.
You can also use /* */ to comment out part of a line should you wish
to.
void foo(int param1, int param2, /* int param3 */);
/* */ comments aren't clever enough to nest so you can get caught out
sometimes if you try to use them to temporarily remove a chunk of code,
for example during debugging, if that chunk of code already contains /*
*/ comments. For example, I might have this function somewhere in my
code.
void foo()
{
// code here
/*
Here is a multi-line comment
to help the reader understand what is going on
*/
// more code here
}
Now suppose I'm debugging. I want to simplify the code to track down
the problem. One of the things I need to do is temporarily comment out
the entire body of foo so it can be eliminated from my investigation.
The easiest way to do that is to add /* immediately after the opening
brace at the start of the function and add */ immediately before the
closing brace at the end of the function. Except with m multi-line
comment in there that won't work. The /* */ comment will end at the end
of the multi-line comment. The later part of the foo function (where I
wrote "more code here") will still be there not commented out. And the
*/ immediately before the closing brace of foo will be a simple syntax
error.
For this reason I personally never use /* */ for comments that I intend
to keep.
Gavin Deane