Invocations of foo(3) and bar(3)

Consider the C functions foo and bar given below:

int foo(int val) {
    int x=0;
    while(val > 0) {
        x = x + foo(val--);
    }
    return val;
}
int bar(int val) {
    int x = 0;
    while(val > 0) {
        x= x + bar(val-1);
    }
    return val;
}

Invocations of foo(3) and bar(3) will result in:

(A) Return of 6 and 6 respectively.

(B) Infinite loop and abnormal termination respectively.

(C) Abnormal termination and infinite loop respectively.

(D) Both terminating abnormally.

2Comments
shivanisrivarshini @shivanisrivarshini
23 Mar 2017 09:46 am

Option C Abnormal termination of foo(3) and infinite loop of bar(3)

Sukannya @sukannyapurkaya
23 Mar 2017 11:48 am

Ya, but why so??

Pages