• edited by
34,190 views
93 93 votes

Consider the following two functions.

void fun1(int n) {
    if(n == 0) return;
    printf("%d", n);
    fun2(n - 2);
    printf("%d", n);
}
void fun2(int n) {
    if(n == 0) return;
    printf("%d", n);
    fun1(++n);
    printf("%d", n);
}

The output printed when $\text{fun1}(5)$ is called is

  1. $53423122233445$  
  2. $53423120112233$                       
  3. $53423122132435$  
  4. $53423120213243$                       

12 Answers

Best answer
137 137 votes

  • Unroll recursion up to a point where we can distinguish the given options and choose the correct one!
  • Options B and D are eliminated.
  • A is the answer.
• edited by
91 91 votes

hence correct answer is a.

8 8 votes

Ans is A 

5 5 votes

A is the correct answer

Answer:
Position:
Show:

Related questions

176 176 votes
10 answers 10 answers
42.1k
42.1k views
Arjun asked Feb 14, 2017
42,083 views
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)...
1 1 vote
1 1 answer
1.1k
1.1k views
soujanyareddy13 asked Apr 12, 2022
1,077 views
Consider the following two functions.void fun1(int n) { if(n == 0) return; printf("%d", n); fun2(n - 2); printf("%d", n); } void fun2(int n) { if(n == 0) return; printf("...
161 161 votes
11 answers 11 answers
44.1k
44.1k views
srestha asked Feb 14, 2017
44,073 views
Consider the following C program.#include<stdio.h #include<string.h void printlength(char *s, char *t) { unsigned int c=0; int len = ((strlen(s) - strlen(t)) c) ? strlen...
115 115 votes
8 answers 8 answers
38.2k
38.2k views
srestha asked Feb 14, 2017
38,197 views
The output of executing the following C program is _______________ .#include<stdio.h int total(int v) { static int count = 0; while(v) { count += v&1; v >>= 1; } return c...