前增量和后增量功能调用 [英] Pre increment and post increment function call
本文介绍了前增量和后增量功能调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#include<stdio.h>
int main()
{
void add();
int i=2;
add(i++,--i);
print("%d",i)
}
void add(int a,int b)
{
print("%d %d",a,b);
}
/* a和b的值是多少,我实际上没有得到为什么b是2的答案*/
/*what are a and b's value i am actually not getting the answer why b is 2 */
推荐答案
在第6行中调用add()的
in line 6 where add() is called
第一个args是i ++,因此它将向函数发送值2,即i的值,然后现在加1,即i = 3.
first args is i++ so it will send value 2 ie value of i to the function and then add 1 now i=3.
第二个参数为--i,现在它将减去1,然后又变为2,然后将值2发送给函数
second args is --i now it will subtract 1 and iwill now be 2 again and then send value 2 to function
所以我认为您的答案会打印出来 2 2(即a和b的值) 2(即i的值)
So I think your answer will print 2 2 (that is value of a and b) 2 (that is value of i)
这篇关于前增量和后增量功能调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文