0

Why it outputs the value not the index ?

#include<stdio.h> int RecursiveLinearSearch(int t[],int size,int value); int RecursiveLinearSearch(int t[],int size,int value){ if (size<0) return -1; else if (t[size]==value) return size; return (t,size-1,value); } int main (){ int t[]={5,9,13,45,33}; int index; index=RecursiveLinearSearch(t,5,45); printf("index=%d",index); return 0; }

2nd Feb 2021, 11:33 AM
Coderalgeria
Coderalgeria - avatar
3 Réponses
0
You forgot the name of the function. return RecursiveLinearSearch(t,size-1,value); Comma is an operator in C/C++ (a, b) == b that's why ((t, size-1), value) returns value.
2nd Feb 2021, 11:52 AM
jtrh
jtrh - avatar
0
You have to write name of the function after the last return statement return RecursiveLinearSearch(t, size-1, value);
2nd Feb 2021, 11:59 AM
Yamin Mansuri
Yamin Mansuri - avatar
0
Yeah,thanks for your answears :)
2nd Feb 2021, 12:00 PM
Coderalgeria
Coderalgeria - avatar