QUIZ 67

What is the difference of values between b and a?

int foo(int c)
{
return ++c;
}

a=b=1;
a+=foo(a=5+foo(foo(a)));

b+=foo1(b=5+foo1(foo1(b)));

a) 0
b) 5
c) 16
d) 11
Answer : (b)
Explanation :

In foo1, post-increment operator is used, so value is first used once, then incremented. So, here it only returns the same value, no effect of the increment operator can be seen

a=a+foo(a=5+foo(foo(a)))
a=a+foo(a=5+foo(2))
a=a+foo(a=5+3)     ——–> a=18
a=a+foo(a=8)         ——–>a=8 gives 8 as input to foo, i.e. foo(8)
a=a+9;
a=8+9=17


b+=foo1(b=5+foo1(1))
b+=foo1(b=5+1)
b+=foo1(6)            ——–> b=6
b=6+6=12

a~b=5

Leave a Reply

Your email address will not be published. Required fields are marked *