会C++语言的请进
答案:1 悬赏:50 手机版
解决时间 2021-03-31 18:27
- 提问者网友:寂寞梧桐
- 2021-03-31 07:32
会C++语言的请进
最佳答案
- 五星知识达人网友:雪起风沙痕
- 2021-03-31 08:05
代码如下:
1 # include
2 #define fun(a) 4*a;
3 int main(void)
4 {
5 int t;
6 t=fun(1+2);
7 printf("t=%d
", t);
8 return;
9 }GCC指定-E选项后可以查看宏展开之后的样子,节选如下:
gcc -E test.c -o test.i837
838 int main(void)
839 {
840 int t;
841 t=4*1+2;;
842 printf("t=%d
", t);
843 return;
844 }运行结果:
zh@zh-CW65S:~/work$ gcc -E test.c -o test.i
zh@zh-CW65S:~/work$ gcc test.c -o test
zh@zh-CW65S:~/work$ ./test
t=6
zh@zh-CW65S:~/work$答案是6,所以宏定义一定要注意括号:建议这样写:
#define fun(a) (4*(a))
1 # include
2 #define fun(a) 4*a;
3 int main(void)
4 {
5 int t;
6 t=fun(1+2);
7 printf("t=%d
", t);
8 return;
9 }GCC指定-E选项后可以查看宏展开之后的样子,节选如下:
gcc -E test.c -o test.i837
838 int main(void)
839 {
840 int t;
841 t=4*1+2;;
842 printf("t=%d
", t);
843 return;
844 }运行结果:
zh@zh-CW65S:~/work$ gcc -E test.c -o test.i
zh@zh-CW65S:~/work$ gcc test.c -o test
zh@zh-CW65S:~/work$ ./test
t=6
zh@zh-CW65S:~/work$答案是6,所以宏定义一定要注意括号:建议这样写:
#define fun(a) (4*(a))
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯