为什么" I"在我的程序变量递增得到两次?
问题描述:
我的一个朋友给我看了这个节目,问我为什么 I
变量递增得到两次。
One of my friend showed me this program and asked me why is i
variable getting incremented twice.
据我的了解 MAX(我+ +,++ j)条;
在这一行 I
是先发的一个参数,然后递增,因此,如果的初始值i
是 10
则增加后的值应 11
,但它显示的增加值 I
为 12
。
According to my understanding MAX(i++, ++j);
in this line i
is first send as a parameter and then incremented, so if the initial value of i
is 10
then the incremented value should be 11
, but it shows the incremented value of i
as 12
.
程序:
#include<stdio.h>
#define MAX(x,y) (x)>(y)?(x):(y)
void main(void)
{
int i = 10;
int j = 5;
int k = 0;
k = MAX(i++, ++j);
printf("%d %d %d",i,j,k);
}
输出:
12 6月11日
有人可以解释我的价值是如何增加到12?
Can someone please explain me how is the value incremented to 12 ?
感谢。
答
您宏替换意味着你写(我++)&GT;(++ J)(我+ +):(++ j)条
。