Thursday, May 21, 2009

Comments with C++

Comments are notes in a program's code that are not read by the computer, only people. In C++, there are two ways to leave comments in your code; Single Line or Multi-Line Comments. You already saw an example of a multi-line comment in the hello world program:
/*A simple Hello World Program for C++ Beginners
Written By
Arikado */

Everything within the "/*" and "*/" characters is a comment and ignored by the computer when executing your program.

Single Line Comments are comments that are only on a single line of code. By typing the characters "//" you are initiating that all of the characters that follow, on that line only, are a comment. Here is an example of a single line comment:

int main(){ //This is a single line comment

Comments are (especially in open source software) important because they allow other people to easily understand your code. When writing any kind of code, always be sure to comment as frequently as possible.


  1. I believe that unarmed truth and unconditional love will have the final word in reality. This is why right, temporarily defeated, is stronger than evil triumphant. See the link below for more info.


  2. I used a lot of emoticons in my sms and in my networking site. I find it cute and interesting. It portraits on my emotions.


  3. Love it! Very interesting topics, I hope the incoming comments and suggestion are equally positive. Thank you for sharing this information that is actually helpful.