标签:http include 事件 define sharp csharp turn alt 输入
不带参数的宏定义
#define PI 3.14
#include<stdio.h> #define R 6371 #define PI 3.14 #define V PI*R*R*4/3 int main(){ int r; float s; printf("输入圆的半径"); scanf("%d",&r); // #undef PI; s=PI*r*r; printf("%.2f",s); }
带参数的宏定义(机械的替换)
#include <stdio.h> #define MAX(x, y) (((x) > (y)) ? (x) : (y)) int main(void) { int x, y; scanf("%d%d", &x, &y); printf("较大的数%d", MAX(x, y)); return 0; }
加小括号防止意外事件的发生
#include <stdio.h> #define SQUARE(x) (x * x) int main(void) { int x; scanf("%d", &x); printf("%d 的平方 %d\n", x, SQUARE(x)); printf("%d 的平方 %d\n", x+1, SQUARE(x+1)); return 0; }
标签:http include 事件 define sharp csharp turn alt 输入
原文地址:https://www.cnblogs.com/helloworld2019/p/11167078.html