鱼C论坛

 找回密码
 立即注册
查看: 2975|回复: 6

S(x) 4*x*x+1宏替换?

[复制链接]
发表于 2015-6-19 10:13:42 | 显示全部楼层
典型的宏替换出现的优先级的问题
#define S(x) 4*x*x+1
S(6+8)         4*6+8*6+8+1          结果自然为81

考虑这样
#define s(x) 4*(x)*(x)+1

  1. #include <stdio.h>
  2. #define S(x) 4*(x)*(x)+1
  3. int main()
  4. {
  5.         int i=6,j=8;
  6.         printf("%d\n",S(i+j));
  7.         return 0;
  8. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-9-27 02:35

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表