using namespace std;
int searchlist(int list[],int n,int value, int foundIndices[])
{
int index = -1;
for(int k=0;k<n;k++)
{
if (list[k]==value)
foundIndices[++index]=k;
}
return (index+1);
}
int main()
{
int tests[6] = {87,75,98,100,82,100};
int results[6] = {-1,-1,-1,-1,-1,-1};
int foundItems = searchlist(tests,6,100,results);
for (int m=0;m<foundItems;m++)
cout<<results[m]<<" ";
Array is passed by reference into the function, because a pointer is passed instead of a clone copy. If the array is modified inside the function, the modifications are applied to the caller's copy. You could declare the array parameter as const to prevent the array from being modified inside the function.