Question

What is wrong with the following function definition? void fill(const int a[], int size) { for...

What is wrong with the following function definition?


void fill(const int a[], int size)
{
for (int i = 0; i < size; i++)
{
    a[i] = 0;
}
return;
}

Answers:

The function cannot change the array parameter.

The array should be passed as a call-by-reference, not call-by-value.

The for loop causes an out-of-bounds indexing error.

Nothing, the code works fine as is.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer: The function cannot change the array parameter.

The function cannot change the array parameter because array declared const. if we declared const on any variable, w we can not change that value.

Add a comment
Know the answer?
Add Answer to:
What is wrong with the following function definition? void fill(const int a[], int size) { for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write the following function: const int MIN_SIZE = 2; const int MAX_SIZE = 8; const int...

    Write the following function: const int MIN_SIZE = 2; const int MAX_SIZE = 8; const int UNKNOWN = 0; const int RED = 1; const int BLUE = 2; const char UNKNOWN_LETTER = '-'; const char RED_LETTER = 'X'; const char BLUE_LETTER = 'O'; const string UNKNOWN_STRING = "unknown"; const string RED_STRING = "X"; const string BLUE_STRING = "O"; /** * Requires: size <= MAX_SIZE and size is a positive even integer, *           0 <= row && row < size....

  • Complete the definition of the following function void find_two_largest (int 3[), int n, int *largest, int...

    Complete the definition of the following function void find_two_largest (int 3[), int n, int *largest, int * second_largest); When passed an array a of length n, the function will search a for its largest element and second largest element, storing them in the two variables pointed to by largest and second_largest, respectively. Test your function in the main function.

  • #include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void...

    #include <iostream> using namespace std; const int SIZE = 10; void displayGreaterThan(int[], int); void displaySmallerThan(int[],int); void displayArrayContent(int[]); void displayLargestValue(int[]); void displaySmallestValue(int[]); int main(){    int number;    int numbers[SIZE] = {9,1,90,98,53,22,76,29,37,65}; cout <<"Enter a number: "; cin >> number; cout << endl;    displayGreaterThan(numbers,number); cout << endl; displaySmallerThan(numbers,number); cout << endl; displayArrayContent(numbers); cout << endl; displayLargestValue(numbers); cout << endl; displaySmallestValue(numbers); cout << endl;    return 0;       } void displayGreaterThan(int value[],int num){ cout << " All larger value(s)than" <<...

  • #include <iostream> #include <fstream> using namespace std; //constants const int CAP = 100; //function prototypes bool...

    #include <iostream> #include <fstream> using namespace std; //constants const int CAP = 100; //function prototypes bool openFile(ifstream &); void readData(ifstream &, int [], int &); void printData(const int [], int); void sum(const int[], int); void removeItem(int[], int &, int); int main() { ifstream inFile; int list[CAP], size = 0; if (!openFile(inFile)) { cout << "Program terminating!! File not found!" << endl; return -1; } //read the data from the file readData(inFile, list, size); inFile.close(); cout << "Data in file:" <<...

  • What does this function do? int mystery(double employees[], double id, int size) { for (int i...

    What does this function do? int mystery(double employees[], double id, int size) { for (int i = 0; i < size; i++) { if (id == employees[i]) { return i; } } return -1; } A. This is a function that performs a search. If the id is found in the employees array, its index location is returned, otherwise -1 is returned. B. This is a function that sorts the employees array C. This is a function that returns all...

  • howthe   output   of   the   following   4   program segments (a)    const int SIZE=8;    int values[SIZE]...

    howthe   output   of   the   following   4   program segments (a)    const int SIZE=8;    int values[SIZE] = {10, 10, 14, 16, 6, 25, 5, 8};    int index;    index=0;    res = values[index];    for (int j=1; j<SIZE; j++)    {        if (values[j] > res)        {            res = values[j];            index = j;        cout << index << res << endl;        }    }    cout <<...

  • How do I do this? -> string print() const; Function to output the data, return the...

    How do I do this? -> string print() const; Function to output the data, return the output in the form of string, with all elements in the hash table included and each seperated by a space this is my code: template <class elemType> string hashT<elemType>::print() const { for (int i = 0; i < HTSize; i++){        if (indexStatusList[i] == 1){        cout <<HTable[i]<< " " << endl;        }   }    } **********Rest of the code...

  • assume we have the following constant declarations const int MAXIMUM = 60; const int letters_Size =...

    assume we have the following constant declarations const int MAXIMUM = 60; const int letters_Size = 15; we then have the function void Adjusting(char C_string[ ] [ ], int amount_words); assume that youve taken in a string from the user now just simply read the input wnd analyze the sentence into its parts and describe its roles basically parse into words and save it and sort into an array of C-strings. note code is in C++ complete the function definition...

  • The function retrieveAt of the class arrayListType is written as a void function. Rewrite this function...

    The function retrieveAt of the class arrayListType is written as a void function. Rewrite this function so that it is written as a value returning function, returning the required item. If the location of the item to be returned is out of range, use the assert function to terminate the program. note: please give all code in c++ below is the class and implementation(a test program would be helpful in determining how to use it): class arrayListType { public:    ...

  • A_____error causes the program to prematurely terminate during execution. ==.!=.>.<= are examples of____operators. A_____loop always executes...

    A_____error causes the program to prematurely terminate during execution. ==.!=.>.<= are examples of____operators. A_____loop always executes its body at least once. The function_______lets the compiler know that the function will be defined later. The_____statement skips to the end of the body of a loop. The_____loop has a header which consists of three sections separated by semicolons. The____of an infinite loop is always true. A(n)____statement cannot exist without an if statement. The_____of a variable tells the compiler which values it can...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT