521 views
0 votes
0 votes
void print(int i){
    static int x=4;
    if(i!=0){
        print(--x);
    }
    printf("%d",x);
}

What will be output printed for print(10)?


Will it print value as call by value or call by reference?

1 Answer

0 votes
0 votes
print(10) -> print(3) -> print(2) -> print(1) -> print(0).

Above mentioned sequence is the function call sequence, as the variable 'x' is declared as static, changes that you make to the variable will persist between function calls. The final value of the variable will be '0'.

Hence the output will be 00000, as we five function calls, x will be printed 5 times.

It's call by value(but the variable we are printing is stored in static memory), and not call by reference.

Related questions

1 votes
1 votes
0 answers
1
Mahbub Alam asked Nov 15, 2018
554 views
what is the result of comparing signed with unsigned number??#include <stdio.h>int main(){ unsigned int a = 5;if(a -1)printf("5 is -1\n"); return 0; }
1 votes
1 votes
0 answers
2
0 votes
0 votes
1 answer
4
dixit bishwash asked Mar 31, 2018
1,176 views
The Correct answer is c but how?int main(){ int a=210,b=120,c; c=a>b?1,2,3:2,5,6,7; printf("%d",c);}ans:-a) 1b) 2c) 3d) Error.