博学而笃志 切问而近思 仁在其中
详情
C语言注释
作者:--     发布时间:2019-11-20     评论:0     阅读:0

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

  • 单行注释
  • 多行注释

1.单行注释

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

#include <stdio.h>      
#include <conio.h>    
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 <stdio.h>      
#include <conio.h>    
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
请按任意键继续. . .


上一篇:C语言运算符
下一篇:测试
相关文章
loading......
最新动态
所有评论

loading......

网站声明:
本站部分内容来自网络,如您发现本站内容
侵害到您的利益,请联系本站管理员处理。
联系站长
373515719@qq.com
关于本站:
编程参考手册