//// Created by a1073 on 2019/7/5.//#include<stdio.h>#define PI 3.14#define R 6371#define V PI * R * R * R * 4 / 3intmain(void){//#undef PI 可以结束PI的作用printf("%d\n", R);printf("%.2f\n", V);return0;}
带参数的宏定义实例
//// Created by a1073 on 2019/7/5.//#include<stdio.h>#define MAX(x, y) ((x) > (y) ? (x) : (y))/*
* MAX(x, y)
* MAX和括号中不能加空格
* 每个参数使用括号包裹*//*
* #define SQUARE(x) x * x
* 如果参数不用括号包裹的话,传入参数为x+1,结果为 x+1*x+1 结果出错
* 避免运算符优先级产生错误
* */intmain(void){int count =10;while(count --){int i, j;scanf("%d %d",&i,&j);printf("%d\n",MAX(i, j));}return0;}