C语言格式说明
C 编程是一种通用的、过程式的、命令式的计算机编程语言。在 C 语言中,我们看到:
- 语句以分号结尾。
- C 语言区分大小写。
- 编译器忽略缩进。
- 字符串用双引号括起来。
- 库函数使用小写字母。
- 换行符通过以下方式处理:
C语言格式
以下是C编程语言的格式说明:
分号
分号在C语言中非常重要。
它告诉编译器一个语句在哪里结束,下一个语句在哪里开始。
如果我们在每个语句之后没有放置分号,将会出现编译错误。
Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.
大小写敏感性
C 语言是一种大小写敏感的语言。虽然 `int` 可以编译通过,但 “Int”、“INT” 或任何其他变体在 C 语言中都无法正常工作。
所有 C 语言关键字都小写。
注释不是必需的
虽然注释不是必需的,但最好在程序开始处添加一个注释,说明程序的目的、作者以及编写日期。
示例程序
以下是使用 C 格式方法计算圆周长的 C 程序:
圆周长公式 = 2 * PI * R。
其中,R 是圆的半径,PI 是一个常数,其值为 3.1415。
示例
#include<stdio.h> //library function are lower case #include<conio.h> #define PI 3.1415 main ( ){ float c, r; //statements are terminated with semicolon printf ("enter radius of circle"); //strings are placed in double quotes scanf ("%f", &r); c = 2 * PI * r; printf ("Circumference = %f", c); getch ( ); }
输出
执行上述程序后,会产生以下结果:
Enter radius of circle 1 Circumference=6.2830
广告