?
Solved

[noob][c++]  comments

Posted on 2007-11-17
5
Medium Priority
?
237 Views
Last Modified: 2010-04-01
how many ways are there in comment in the c++ language?


I know   //


are there any others?
0
Comment
Question by:Troudeloup
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 7

Accepted Solution

by:
UrosVidojevic earned 400 total points
ID: 20303862
- 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
 
LVL 40

Assisted Solution

by:evilrix
evilrix earned 400 total points
ID: 20303886
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
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 800 total points
ID: 20303910
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
 
LVL 53

Assisted Solution

by:Infinity08
Infinity08 earned 800 total points
ID: 20303913
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
 
LVL 11

Assisted Solution

by:Deepu Abraham
Deepu Abraham earned 400 total points
ID: 20303951
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question