Commenting in C

Commenting in the C language is used to give out the information about the lines of the code which are included. It is one of the things that is widely used for the documentation. They are the part of the code snippets which will directly be ignored by the compiler as they have no programmatical use in that particular application.

They are the type of concept that makes every programming code and application more readable and efficient to the programmer or a user and helps the programmer by explaining the logic behind the code.

It is said that a well documented program is a good practice for every developer and also makes the debugging more easier as anyone can find the commented section and what function it does.

It can be considered the sentence that only a programmer reads and the compiler does not, which is the explanation or the annotation of the main code. Neither the compiler nor the interpreter executes or reads the commented part, and it will directly be ignored by the computer.

Comments can be a detailed or precise description of the source code of a program or explanations.

There are two types of comments used in the C programming language.

  1. Single line comments
  2. Multi line comments

Single line comments: They are the type of comments that use double slash, represented as following “//” to comment on a specific part of any program or application.



Multi line comments: They are the type of comments that start and end with a symbol including a slash with an asterisk represented in the following manner “/*…. */”. This type of commenting slash can be placed anywhere within the code or application, and the sentences in between the slashes will be commented. It can be filled with any number of characters and any number of lines. It should be sure that the closing of multi line comments should be done correctly else the whole program will throw an error.



You can also create a comment that displays at the end of a line of code. But generally, it’s a better practice to put the comment before the line of code.

When are comments in programming necessary tools?

  1. If no comments regarding the program’s features are given, a person reading a big code will be perplexed.
  2. Comments are a method to put additional details into a code to make it more understandable.
  3. If comments are not included in an extensive code base, the reader will be perplexed. To make code more intelligible, comments might describe an algorithm.
  4. If code is to be reused over a lengthy period of time, comments might be helpful for one as well.
  5. A good programmer who produces codes that are only understood by the machine is better than the one who generates codes that were only comprehended by the machine.
  6. As a result, including comments to your code is highly recommended as a good programming technique. Comments do not affect programming since they are overlooked by the compiler.
  7. Comments help the developer understand the logic/algorithm of the code if he revisits it after a long time.

Pin It on Pinterest

Share This