Q18. “Comments are useful and easy way to enhance readability and understand-ability of a program.” Elaborate with examples.
Ans. Comments are pieces of code that the compiler discard or simply does not execute. The purpose of comments is only to allow the programmer to inert some notes or descriptions to enhance readability or understand-ability of the program.
There are two ways to insert comments in C++ programs:
- Single line comment with //
The comments that begins with // are single line comments. The compiler simply ignores everything following // in that same line.
- Multiline or block comments with /*…..*/
The block comments, mark the beginning of comment with /* and end with */. That means, everything that falls between /* and */ is considered a comment even though it is spread across many lines.