Pre increment and post increment function call

2019-09-20 17:41发布

问题:

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