100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > c语言预编译问题

c语言预编译问题

时间:2020-05-28 10:18:13

相关推荐

c语言预编译问题

《程序设计基础-c语言》杨莉 刘鸿翔 ISBN-978-7-03-032903-5 p241习题7

10.若有以下定义:

#define X(x) ((x)*(x))#define Y(x) (X(x)*(x)*X(x))#define Z(x) (Y(x)*X(x))

问:下面表达式的替换结果是什么?

X(m)+Y(n)+Z(x)

宏展开,替换为:

X(m) ---> ( (m)*(m) )1 * 1Y(n) ---> ( (n)*(n) ) * (n) * ( (n)*(n) )2 * 2 * 2 * 2 * 2Z(x) ---> ( (x)*(x) ) * (n) * ( (x)*(x) )*( (x)*(x) )*(x)3 * 3 * 3 * 3 * 3 * 3 * 3 * 3

如果m=1 , n=2 , x=3,结果如下:

#include<stdio.h>#define X(x) ((x)*(x))#define Y(x) (X(x)*(x)*X(x))#define Z(x) (Y(x)*X(x))int main(){printf("%d\n",X(1)+Y(2)+Z(3));printf("%d\n",X(1));printf("%d\n",Y(2));printf("%d\n",Z(3));return 0;}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。