Comments in c

Comments in c, generally in programming, are used to explain some parts of the code and make it more readable. Moreover, it is possible to prevent the execution of some lines of the code when testing alternative code. Comments are categorized into single-line and multi-line.

Single-line comments

The first kind of comment starts with two forward slashes (//). Anything between // and the end of the line will be ignored by the compiler. Look at the following example:

#include <stdio.h> //This line includes a standard library
// This text is comment.
print("Comment");

As you can see, it is possible to use a single-line comment at the beginning of a line or after the end of a statement.

Multi-line comments

With this kind of comment, it is possible to comment on several lines. To do that, we use /* */ and write the comment between two *.

/* #include <stdio.h> This line includes a standard library
This text is comment.*/
print("Comment");
Was this helpful?
[0]
Scroll to Top
Scroll to Top