GATE Assistant

Past questions › Computer Science and Information Technology › GATE 2026 set1

GATE 2026 set1 · CS · NAT · 2 marks · Programming and Data Structures › Recursion

GATE 2026 set1 Computer Science and Information Technology question: Consider the recursive functions represented by the following code segment: code The…

Consider the recursive functions represented by the following code segment:

int bar(int n){
     if (n == 1) return 0;
     else return 1 + bar(n/2);
}
int foo(int n){
     if (n == 1) return 1;
     else return 1 + foo(bar(n));
}

The smallest positive integer for which foo() returns 5 is ______. (answer in integer)

Note: Ignore syntax errors (if any) in the function.

Show answer

Official answer: 65536

Practise this question with exam-style marking

Discussion

No discussion yet.

Join the discussion