Comments in C Programming

0
In C programming, comments are used to provide explanations and improve the readability of the code. They are ignored by the compiler and do not affect the execution of the program. This article will explore the usage and rules of comments in C.

In C, there are two types of comments:
  • Block comments: These begin with `/*` and end with `*/`. The contents of such a comment are examined only to identify multibyte characters and to find the characters `*/` that terminate it. Block comments do not nest, meaning you cannot have a block comment inside another block comment.
  • Line comments: These begin with `//` and include all multibyte characters up to, but not including, the next new-line character. The contents of such a comment are examined only to identify multibyte characters and to find the terminating new-line character.
Here are some examples of comments in C:
C
"a//b" // four-character string literal
#include "//e" // undefined behavior
// */ // comment, not syntax error
f = g/**//h; // equivalent to f = g / h;
//\
i(); // part of a two-line comment
/\
/ j(); // part of a two-line comment
#define glue(x,y) x##y
glue(/,/) k(); // syntax error, not comment
/*//*/ l(); // equivalent to l();
m = n//**/o
+ p; // equivalent to m = n + p;
Tags

Post a Comment

0Comments
Post a Comment (0)