001、不使用对象式宏
[root@localhost test]# ls test.c [root@localhost test]# cat test.c ## 测试程序 #include <stdio.h>int main(void) {int i, sum = 0;int v[5] = {3, 8, 2, 4, 6}; ## 定义int【5】 型数组for(i = 0; i < 5; i++){sum += v[i];}printf("sum = %5d\n", sum);printf("mean = %.5f\n", (double)sum/5); ## 求和和均值return 0; } [root@localhost test]# gcc test.c ## 编译 [root@localhost test]# ls a.out test.c [root@localhost test]# ./a.out ## 执行程序 sum = 23 mean = 4.60000
002、使用对象式宏