In C, comments are used to provide explanatory notes within the code. They are ignored by the compiler and do not affect the execution of the program.
There are two types of comments in C:
- Single-Line Comments
- Multi-Line Comments
1. Single-Line Comments
These are created using two forward slashes (//) and everything following them on the same line is treated as a comment.
// This is a single-line comment in C
2. Multi-Line Comments
These are created using /* to start the comment and */ to end the comment. Everything between the start and end delimiters is treated as a comment.
/* This is a multi-line comment in C */
It is a good practice to use comments to explain the code and make it more readable and understandable for other developers who may read or modify the code in the future.