A well-documented program is a good practice as a programmer. It makes a program more readable and error finding become easier. One important part of good documentation is Comments.
- In computer programming, a comment is a programmer-readable explanation or annotation in the source code of a computer program
- Comments are statements that are not executed by the compiler and interpreter.
In C/C++ there are two types of comments :
- Single line comment
- Multi-line comment
Single line Comment
Represented as // double forward slash
It is used to denote single line comment. It apply comment to a single line only. It is refereed as C++-style comments as it is originally part of C++ programming.
// single line comment
Welcome to GeeksforGeeks
Represented as /* any_text */ start with forward slash and asterisk (/*) and end with asterisk and forward slash (*/).
It is used to denote multi-line comment. It can apply comment to more than a single line. It is referred as C-Style comment as it was introduced in C programming.
/*Comment starts continues continues . . . Comment ends*/
Welcome to GeeksforGeeks
Comment at End of Code Line
You can also create a comment that displays at the end of a line of code. But generally its a better practice to put code before the line of code.
int age; // age of the person
When and Why to use Comments in programming?
- A person reading a large code will be bemused if comments are not provided about details of the program.
- Comments are a way to make a code more readable by providing more description.
- Comments can include a description of an algorithm to make code understandable.
- Comments can be helpful for one’s own self too if code is to be reused after a long gap.
- Comments in Java
- Concept of Comments in Computer Programming
- Types of Regression Techniques
- Python | Linear search on list or tuples
- Responsive images in Bootstrap with Examples
- Borders in bootstrap with examples
- access command in linux with examples
- compress command in Linux with examples
- Displaying inline and multiline blocks of code using Bootstrap
- Step by Step guide to Write your own WordPress Template
- bzless command in Linux with examples
- Print multiples of Unit Digit of Given Number
- CSS | @media Rule
- HTML | DOM Style backgroundClip Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.