Examveda

What does the following code do?
#include<stdio.h>
int search_num(int *arr, int num, int len)
{
     int i;
     for(i = 0; i < len; i++)
     if(arr[i] == num)
      return i;
     return -1;
}
int main()
{
      int arr[5] ={1,2,3,4,5},num=3,len = 5;
      int indx = search_num(arr,num,len);
      printf("Index of %d is %d",num,indx);
      return 0;
}

A. Search and returns the index of all the occurrences of the number that is searched

B. Search and returns the index of the first occurrence of the number that is searched

C. Search and returns of the last occurrence of the number that is searched

D. Returns the searched element from the given array

Answer: Option B


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

Join The Discussion

Related Questions on Miscellaneous on Data Structures