ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

03 – C++ : Comments

Cplusplus Comments

We can say that program comments are important when you are writing a C++ code for your program because it serves as explanatory statements or let’s just say it’s a note to yourself that you put in the sourcecode ( best done before you actually write the codes ). These comments also help anyone reading the sourcecode and make them understand what you’re trying to do.

 

You can write as many characters as you like because C++ supports single line and multi-line comments. And don’t worry because all comments are ignored by the complier.

 

/* is used when you start to write C++ comments and it ended up with */.

Example:

/* Example of comment */

/* comments in c++  can also be
 * in multiple lines
 */

 

You can also start with //, enhancing to the end of the line.

Example:

#include <iostream>
using namespace std;

main()
{
   cout << "Howdy World...."; // Display Howdy World....

   return 0;
}

 

In the example above,  it will ignore the // Display Howdy World….  and execute the codes that you put. This will be the result.

Howdy World.....

 

Inside the /* and  */ the code have no value at all. See example below.

 

/* Comment out Displaying of Howdy World....:

cout << "Howdy World...."; // Display Howdy World....

*/
Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!