Moving to another question will save this response uestion 66 A function, as sho
ID: 3578708 • Letter: M
Question
Moving to another question will save this response uestion 66 A function, as shown in the following code snippet. The programmer was programmer writes the sum array int sum array (int arr int size int result e, for (int i es i size, i i 2) result result arr[i]; return result, int main() int sum array(int arr[], int size), int num[5] {1, 2, 3, 4, 5)i int sum sum array(num, 7) cout "Sum: sum endli return 03 A. The main function passes an incorrect size for the num array. B. It is not possible to pass an array as an argument to a function. o c he sum array function works only with an array th an even number of values. wit O D. The main function does not initial the num array correctly before passing it to the sum array func A Moving to another question will save this responseExplanation / Answer
#include <iostream>
using namespace std;
//The elements in the array are summated, and the sum is returned.
//Nothing wrong with this function.
int sum_array(int arr[], int size)
{
int result = 0;
for(int i = 0; i < size; i += 2)
result += arr[i];
return result;
}
int main()
{
int sum_array(int arr[], int size);
int num[5] = {1, 2, 3, 4, 5}; //An array of size 5 is declared, and is assigned values.
int sum = sum_array(num, 7); //Here the function is called with improper array size.
cout<<"Sum: "<<sum<<endl;
return 0;
}
Therefore, the reason for unexpected behavior of the code is:
A. The main function passes an incorrect size for the num array.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.