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; }
3 Respostas
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.
0
You have to write name of the function after the last return statement
return RecursiveLinearSearch(t, size-1, value);
0
Yeah,thanks for your answears :)