C语言中的注释用于提供有关代码行的信息,它被广泛用于记录代码(或对代码功能实现的说明)。在C语言中有两种类型的注释,它们分别如下 -

单行注释

多行注释

1.单行注释

单行注释由双斜杠//表示,下面我们来看看一个单行注释的例子。创建一个源文件:single_line_comments.c,代码如下 -

#include

#include

void main(){

// 这是一个注释行,下面语句打印一个字符串:"Hello C"

printf("Hello C"); // printing information

// 这是另一个注释行,下面语句求两个变量的值

int a = 10, b = 20;

int c = 0;

c = a + b;

printf("The sum of a+b is :%d", c);

}

执行上面示例代码,得到以下结果 -

Hello C

The sum of a+b is :30

请按任意键继续. . .

2.多行注释

多行注释由斜杠星号/* ... */表示。它可以占用许多行代码,但不能嵌套。语法如下:

/*

code

to be commented

line 3

line n...

*/

下面下面来看看看C语言中的多行注释的例子。

创建一个源文件:multi_line_comments.c,代码如下 -

#include

#include

void main() {

/*printing

information*/

printf("Hello C\n");

/*

多行注释示例:

下面代码求两个数的乘积,

int a = 10, b =20;

int c = a * b;

*/

int a = 10, b = 20;

int c = a * b;

printf("The value of (a * b) is :%d \n", c);

}

执行上面示例代码,得到以下结果 -

Hello C

The value of (a * b) is :200

请按任意键继续. . .

¥ 我要打赏

纠错/补充

收藏

加QQ群啦,易百教程官方技术学习群

注意:建议每个人选自己的技术方向加群,同一个QQ最多限加 3 个群。

更多推荐

c语言怎么写注释,C语言注释