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
http://arikadosblog.blogspot.com */

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.

No comments:

Post a Comment