All programming languages let you include comments in your programs. Comments can be used to remind yourself (and others) of what processing is taking place or what a particular variable is being used for. They can be used to explain or clarify any aspect of a program which may be difficult to understand by just reading the programming statements.
This is very important since the easier it is to understand a program, the more confidence you will have that it is correct. It is worth adding anything which makes a program easier to understand.
Remember that a comment (or lack of it) has absolutely no effect on how the program runs. If you remove all the comments from a program, it will run exactly the same way as with the comments.
Each language has its own way of specifying how a comment must be written. In C, we write a comment by enclosing it within /* and */, for example:
/* This program prints a greeting */
A comment extends from /* to the next */ and may span one or more lines. The following is a valid comment:
/* This program reads characters one at a time
and counts the number of letters found */
C also lets you use // to write one-line comments. The comment extends from // to the end of the line, for example:
a = s * s; //calculate area; store in a
In this series, we will use mainly one-line comments.
No comments:
Post a Comment