题目,为以下程序写一个主函数,并查看展开式和输出结果: #include "stdio.h" #define NL putchar('\n') #define PR(format,value) printf("value=%format\t",(value)) //%f是固定格式,双引号里出现相同字符不进行替换 #define PRINT1(f,x1) PR(f,x1);NL #define PRINT2(f,x1,x2) PR(f,x1);PRINT1(f,x2) #define AA i am student #define N(x) printf(" x \n") #define BB "i am a student" #define M(x) printf(x)
时间: 2024-02-28 22:56:04 浏览: 28
好的,以下是为给定程序编写的主函数并展开式和输出结果:
```c
#include "stdio.h"
#define NL putchar('\n')
#define PR(format,value) printf("value=%" #format "\t",(value)) // 使用 # 将 format 转化为字符串
#define PRINT1(f,x1) PR(f,x1);NL
#define PRINT2(f,x1,x2) PR(f,x1);PRINT1(f,x2)
#define AA "i am student"
#define N(x) printf(#x " = %d\n", x) // 使用 # 将 x 转化为字符串
#define BB "i am a student"
#define M(x) printf("%s", x)
int main() {
int a = 10;
float b = 3.14159;
PRINT2(%d, a, a + 10);
PRINT2(%f, b, 2.0 * b);
PRINT1(%s, AA);
N(a);
M(BB);
return 0;
}
```
展开式:
```
PRINT2(%d, a, a + 10) -> PR(%d, a); PRINT1(%d, a + 10) -> printf("value=%d\t", (a)); putchar('\n'); printf("value=%d\t", (a + 10)); putchar('\n');
PRINT2(%f, b, 2.0 * b) -> PR(%f, b); PRINT1(%f, 2.0 * b) -> printf("value=%f\t", (b)); putchar('\n'); printf("value=%f\t", (2.0 * b)); putchar('\n');
PRINT1(%s, AA) -> PR(%s, AA); putchar('\n'); -> printf("value=%s\t", "i am student"); putchar('\n');
N(a) -> printf("a = %d\n", a); -> printf("a = %d\n", 10); -> a = 10
M(BB) -> printf("%s", "i am a student"); -> i am a student
```
输出结果:
```
value=10 value=20
value=3.141590 value=6.283180
value=i am student
a = 10
i am a student
```
相关推荐
![application/msword](https://img-home.csdnimg.cn/images/20210720083327.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)