Pre increment and post increment function call

2019-09-20 18:05发布

#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条回答
做个烂人
2楼-- · 2019-09-20 18:09

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)

查看更多
登录 后发表回答