Pre increment and post increment function call

随声附和 提交于 2019-12-25 17:39:27

问题


#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);
}

/*what are a and b's value i am actually not getting the answer why b is 2 */


回答1:


in line 6 where add() is called

first args is i++ so it will send value 2 ie value of i to the function and then add 1 now i=3.

second args is --i now it will subtract 1 and iwill now be 2 again and then send value 2 to function

So I think your answer will print 2 2 (that is value of a and b) 2 (that is value of i)



来源:https://stackoverflow.com/questions/23926779/pre-increment-and-post-increment-function-call

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!