How do you comment in the C programming language?

In C language, there are two ways to comment: single-line comments and multi-line comments.

  1. Single-line comment: Starting with two slashes (//), the content after the line will be treated as a comment and will not be compiled or executed.
    Example:
// 这是一个单行注释
int x = 10; // 这是定义一个整型变量并初始化为10
  1. The sentence starts with an asterisk and a forward slash.
/* 
这是一个多行注释,
可以跨越多行,
在这段注释中可以写任意内容。
*/
int y = 20; // 这是定义一个整型变量并初始化为20

Note: Nested multiline comments cannot be used, which means that another multiline comment cannot be included within one multiline comment.

bannerAds