为什么是“i"?变量在我的程序中增加了两次? [英] Why is "i" variable getting incremented twice in my program?
本文介绍了为什么是“i"?变量在我的程序中增加了两次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的一个朋友向我展示了这个程序,并问我为什么 i
变量会增加两次.
One of my friend showed me this program and asked me why is i
variable getting incremented twice.
根据我的理解MAX(i++, ++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 ?
谢谢.
推荐答案
你的宏替换意味着你写 (i++)>(++j)?(i++):(++j)
.
Your macro substitution means that you write (i++)>(++j)?(i++):(++j)
.
这篇关于为什么是“i"?变量在我的程序中增加了两次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文