What is a Comment in C?
Comments are an important part of any program. They help a person writing a program and anyone else who must read the source file, understand what’s going on.
The compiler ignores comments so they can be read by humans but are invisible to the compiler
Comments start with a slash-asterisk “ / * “ and end with an asterisk-slash “ */ “.
Some comments on comments
- Comments are delimited by `/*’ (slash-star) and `*/ (star-slash)’.
- Any text between the first `/*’ and the next `*/’ is ignored by the compiler, irrespective of the position of line breaks.
- Comments can span multiple lines.
- Any string of symbols placed between the delimiters /* and */
- Comments can’t be nested (be careful!)
Here are some examples of valid comments.
/* This is a comment */ /* here is another one that spans two lines */ i = /* a big number */ 123456; i = 123456; /* a comment starts here i = i + 2; this statement is also part of the comment */
Example 1:
#include <stdio.h> /* in this example we find out the area of a circle whose radius is 2.5 and this example shows how to use single and multi line comments */ void main(void) { float pi=3.1416; float rad=2.5; float area=pi*rad*rad; // this formula denotes the area of a circle printf("The area of a circle is %f",area); }
Comments in C
Support us by sharing this post