1.c编译预处理的命令单词主要有如下七个
#define #include #undef #ifdef #ifndef #endif #line
2.符号常量
例如
#define PI3.1415926 ()
其中,PI是定义的符号常量,程序编译时,用3.1415926代替所有的PI。
已知圆的半径radius,求圆的面积area。
#include <stdio.h>
#define PI 3.1415926
void main()
{
int radius;
float area;
radius = 10;
area = PI * radius * radius;
printf("area = %f",area);
}
程序运行结果:
area = 314.159260
3.变量
#include <stdio.h>
void main()
{
int number = 100;
float weight = 100.0,height;
height = 1.80;
printf("number = %d,weight = %f,height = %f\n",number,weight,height);
printf("number 的地址是:%ld",&number);
}
程序运行结果:
number = 100,weight = 100.000000,height = 1.800000
number = 1245052