Examveda

What is the output of the following code?
#include<stdio.h>
int recursive_search_num(int *arr, int num, int idx, int len)
{
     if(idx == len)
      return -1;
     if(arr[idx] == num)
      return idx;
     return recursive_search_num(arr, num, idx+1, len);
}
int main()
{
      int arr[8] ={-11,2,-3,0,3,5,-6,7},num = -2,len = 8;
      int indx = recursive_search_num(arr,num,0,len);
      printf("Index of %d is %d",num,indx);
      return 0;
}

A. Index of -2 is 1

B. Index of -2 is 0

C. Index of -2 is -1

D. None of the mentioned

Answer: Option C


This Question Belongs to Data Structure >> Miscellaneous On Data Structures

Join The Discussion

Related Questions on Miscellaneous on Data Structures