Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

#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 */

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
361 views
Welcome To Ask or Share your Answers For Others

1 Answer

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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...