Solved

[noob][c++]  comments

Posted on 2007-11-17
5
228 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 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

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 shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

733 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