Need help please: Returns the product of all the values in the data array Does n
ID: 3540823 • Letter: N
Question
Need help please:
Returns the product of all the values in the data array
Does nothing because the data array does not exist
Fails because the size of the array is not known
Returns the sum of the values in the data array
zero for first element, junk values for all the others
junk values
all zeros
None of the above
5
9
3
7
visible to all functions defined in the program.
visible only to main.
visible only to the first block after it is declared.
not visible to any functions; it will cause a compile error.
will cause a compiler error.
is a C-style string.
will cause a run-time error.
All of the above
strcpy(s2, s1) ;
strcmp(s1, s2) ;
strcpy(s1, s2) ;
stringcopy(s2, s1) ;
Explanation / Answer
6. (TCO 6) What does the following function do?
double calc ( double data[ ], int size )
{
double s = 1;
for(int i = 0; i < size; i++)
{
s *= data[i];
// takes each data from array using index i and returns the product.
}
return(s);
}
Returns the product of all the values in the data array
7. (TCO 6) The initial values of the elements of foo are _______.
double foo[500] = {0.0};
all zeros is correct ANSWER // in C++, this is one way of completly intialzing the array with zeros.
8.(TCO 6) For the array declared below, what is the sum of list[2] and list[3]?
int list[]= {1,2,3,4,5};
list[0] = 1;
list[1] = 2;
list[2] = 3;
list[3] = 4;
sum is 3+4 = 7. IS CORRECT ANSWER.
9. A variable declared before all blocks in a program is (Points : 5)
that will be come global variable and thus visible to all functions defined in the program
10. null-terminated character array (Points : 5)
is a C-style string. // STANDARD C style string ends with null characters.
11. (TCO 7) Which of the following functions would correctly copy C string s2 to C string s1? (Points : 5)
strcpy(s1, s2) ; is correct answer.
second argument should be source from where we want to copy in this case it should be s2.
first argument should be destination to where we want copy in this case it should be s1.