#1. C Comments
The comments in C are human-readable explanations or notes in the source code of a C program. A comment makes the program easier to read and understand. These are the statements that are not executed by the compiler or an interpreter.
It is considered to be a good practice to document our code using comments.
In programming, comments are hints that a programmer can add to make their code easier to read and understand. For example,
#include <stdio.h>
int main() {
// print Hello World to the screen
printf("Hello World");
return 0;
}
Output
Hello World
Here, // print Hello World to the screen
is a comment in C programming. Comments are completely ignored by C compilers.
When and Why to use Comments in C programming?
- A person reading a large code will be bemused if comments are not provided about details of the program.
- C Comments are a way to make a code more readable by providing more descriptions.
- C Comments can include a description of an algorithm to make code understandable.
- C Comments can be used to prevent the execution of some parts of the code.
Types of comments in C
In C there are two types of comments in C language:
- Single-line comment
- Multi-line comment
1. Single-line Comment in C
A single-line comment in C starts with ( // ) double forward slash. It extends till the end of the line and we don’t need to specify its end.
Syntax of Single Line C Comment
// This is a single line comment
2. Multi-line Comment in C
The Multi-line comment in C starts with a forward slash and asterisk ( /* ) and ends with an asterisk and forward slash ( */ ). Any text between /* and */ is treated as a comment and is ignored by the compiler.
It can apply comments to multiple lines in the program.
Syntax of Multi-Line C Comment
/*Comment starts
continues
continues
.
.
.
Comment ends*/
Upcoming C Basics: Compiling the First C Program
Feel free to look back on C Introduction: “Hello, World!”