Comments are the information provided to understand what the following code is going to do. It helps in describing the program. However, they are not parsed by the software, or, in other words, it does not affect the final piece of code. Comments are just the piece of information for the understanding of the programmer. It is a good habit to write comments in a program to make it understandable.
Comments are of four types:
- Single Line comments
- Multi Line comments
- Trailing comments
- Default comments
Single Line comments
Single line comments are the comments written in one line. The line is started with a double forward slash, (//). The text or code following the double slash is ignored during compilation. We can write any kind of information after this double forward slash may be to provide information or commenting any code if not needed.
Example:
Multiple Line comments
Multiple line comments are comments written in many lines. The comment’s start symbol is (/*) and an end symbol is (*/). Any information which is written in between these two symbols is treated as a comment. It is useful for commenting out large blocks of code or giving large chunk of information.
Example:
Trailing comments
A trailing comment is a kind of single line comment only but differs slightly. Here, the double slash (//)appears at the end of a line for providing the information about the line of code in same line. The code written before the comment symbol is treated as a piece of code from the program. Text written after the symbol is treated as comment.
Example:
Default comments
Default comments are the comments written by the program itself when you create a new project to work on. The line is started with a triple forward slash, (///). The text or code following the triple slash is ignored during compilation similar to single line comment. The comments after the forward slashes are written as XML tags within the “<>” symbols. The information after these forward slash provide information about what you need to write after this line of comment or any entry point or what next code should contain.
Example: