Question: Explain what the following program does.
#include <iostream>
using namespace std;
int whatIsThis( int [], int);
int main()
{
const int arraySize = 10;
int a[arraySize] = {1,2,3,4,5,6,7,8,9,10};
int result = whatIsThis(a, arraySize);
cout << “Result is “ << result << endl;
return 0;
}
//what does this function do?
int whatIsThis(int b[], int size)
{
if (size == 1)
return b[0];
else
return b + whatIsThis (b, size – 1);
}
---------------------------------------------------
Here are my answer.... plz check am i correct?
Explain what the following program does.
My answer: FOUND OUT TOTAL VALUE OF MULTIDIMENSIONAL ARRAY
#include <iostream>
using namespace std;
int whatIsThis( int [], int); // PROTOTYPE < whatIsThis - ARRAY SEARCH >
int main()
{
const int arraySize = 10; // SIZE OF ARRAY
int a[arraySize] = {1,2,3,4,5,6,7,8,9,10}; // CREATE ARRAY
int result = whatIsThis(a, arraySize);
cout << “Result is “ << result << endl;
return 0;
}
//what does this function do?>> //COMPARE KEY TO EVERY ELEMENT OF ARRAY UNTIL LOCATION IS FOUND OR UNTIL END ARRAY REACHED AND THEN SUM THE AMOUNT OF TOTAL ARRAYS FOUND. // <<int whatIsThis(int b[], int size)
{
if (size == 1)
return b[0];
else
return b + whatIsThis (b, size – 1);
}