Ask Question
20 June, 00:25

Given the following function definition, what modifications need to be made to the search function so that it finds all occurrences of target in the array? int search (const int array[], int target, int numElements) {int index=0; bool found=false; while ((! found) && (index < numElements)) {if (array[index] = = target) found=true; elseindex++; }if (found==true) return index; elsereturn - 1; }a. Add another parameter to indicate where to stop searchingb. Add another parameter to indicate where to start searchingc. This already can find all occurrences of a given targetd. Have the function return the whole array

+5
Answers (1)
  1. 20 June, 03:04
    0
    D. have function return the whole array

    Explanation:

    the given function only return first occurrence of target. In order to get all occurrences of target we have to change condition in while loop to check whole array even if first occurrence of target found and plus add another parameter of type array that will store different indexes of occurrence of target and return that array
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Given the following function definition, what modifications need to be made to the search function so that it finds all occurrences of ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers