GATE Assistant

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

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

GATE 2025 set1 Computer Science and Information Technology question: code The value printed by the given C program is . (Answer in integer)

#include <stdio.h>
int foo(int S[],int size){
    if(size == 0) return 0;
    if(size == 1) return 1;
    if(S[0] != S[1]) return 1+foo(S+1,size-1);
    return foo(S+1,size-1);
}
int main(){
    int A[]={0,1,2,2,2,0,0,1,1};
    printf("%d",foo(A,9));
    return 0;
}

The value printed by the given C program is _______ . (Answer in integer)

Show answer

Official answer: 5

Practise this question with exam-style marking

Discussion

No discussion yet.

Join the discussion