Pages

Adhexa

Thursday, July 22, 2010

Comments in C and C++

It's also possible to add comments to your C/C++ program. Comments are added to a program to make it more readable and it helps others to know what your program does. The compiler ignores the comments completely. Comments are very important in any programming language because you will soon forget what you did and why you did it. It will be much easier to modify or fix a well commented program a year from now than one with few or no comments.
A good programming practice is to include a comment prior to the program with a short introductory description about the program. Comments can be added in program in two ways line comment and block comment. The way comments are added is demonstrated in the following example.
#include <stdio.h>
main (){
printf(“Hello World”); // this is a line comment
/* and this
comment
is a block comment*/
}

No comments:

Post a Comment