Write an overload function "searchArray" so that it takes an
array "ary" of int or char, and additional argument,
namely "valu" with type as same as the "ary". A call to this
function will return the index of "valu" within "ary" or -1
if it does not exist.

and this is what i could write for now ..

int searchArray ( int ary[ ],int a){
for ( int i=0;i<=ary.length;i++){
if (ary[i]== a)
return i;
return -1;


it's not complete ..
any one can help me and make it 100% work


7 Years
Discussion Span
Last Post by vmanes

for the general search function, take the else return -1 out of the for loop. That return statement should only execute if you complete the for loop and don't find the search value. int ary[] does not have a length member. You will have to pass the array length as an additional parameter.

If you google C++ templates you'll find a wealth of information on how to use them - as well as, maybe, reading your textbook? Take a stab at it and show us your work then.

Edited by vmanes: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.