Solved

[noob][c++]  comments

Posted on 2007-11-17
5
207 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
5 Comments
 
LVL 7

Accepted Solution

by:
UrosVidojevic earned 100 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 100 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 200 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 200 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:DeepuAbrahamK
DeepuAbrahamK earned 100 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now