Add Comments to a Program

A comment is a note to yourself (or others) that you put into your source code. All comments are ignored by the compiler. They exist solely for your benefit. Comments are used primarily to document the meaning and purpose of your source code, so that you can remember later how it functions and how to use it. You can also use a comment to temporarily remove a line of code. Simply surround the line(s) with the comment symbols.

In C, the start of a comment is signalled by the /* character pair. A comment is ended by */. For example, this is a syntactically correct C comment:

/* This is a comment. */

Comments can extend over several lines and can go anywhere except in the middle of any C keyword, function name or variable name. In C you can't have one comment within another comment. That is comments may not be nested. Lets now look at our first program one last time but this time with comments:

main() /* main function heading */

{

printf("\n Hello, World! \n"); /* Display message on */

} /* the screen */

This program is not large enough to warrant comment statements but the principle is still the same.


Learn More :