#include<stdio.h>
#include<conio.h>
main()
{
//clrscr(); //clears the screen
printf("This program explains comments"); /*how to use comment*/
}
// use for single line comment
/* use for multiple line comment*/
// clrscr(); not support in dev c++ compiler,defined in header file <conio.h>
In C, comments are used to add human-readable explanations and notes to the source code. There are two ways to add comments in C:
- Single-line comments: These are used to add comments that span only one line. A single-line comment starts with the characters
//
and continues until the end of the line. For example:
// This is a single-line comment
- Multi-line comments: These are used to add comments that span multiple lines. A multi-line comment starts with the characters
/*
and ends with the characters*/
. Everything between these characters is considered a comment. For example:
/*
This is a multi-line comment.
It can span multiple lines.
*/
It’s important to note that the characters /*
and */
are not treated as special characters within a string or character constant, so if you want to include them in string or character constant, you need to escape them using backslash.
It’s also a good practice to add comments in your code to explain what the code is doing, especially for complex or non-obvious code. Comments help make the code more readable and easier to understand for other developers who may need to work with it in the future.
Thanks
How to use comments in C language