• edited by
34,927 views
94 94 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
139 139 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
92 92 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

178 178 votes
10 answers 10 answers
43.2k
43.2k views
Arjun asked Feb 14, 2017
43,209 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,085 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("...
163 163 votes
11 answers 11 answers
45.5k
45.5k views
srestha asked Feb 14, 2017
45,465 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
39.2k
39.2k views
srestha asked Feb 14, 2017
39,150 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...