Question 28 To pass a onedimensional array by reference you
Question 28
To pass a one-dimensional array by reference, you __________.
must include the address-of (&) operator before the array\'s name
must include the number symbol (#) before the array\'s name
do not have to do anything because arrays are automatically passed by reference
-----------------------------------------------
Question 29
Assuming that the message variable contains the string \"Happy holidays\",
the statement
message.find(\"days\");
returns _________________.
-1
10
11
day
-----------------------------------------------
Question 30
A _____________ is a single item of information about a person, place, or thing.
data file
field
program file
record
-----------------------------------------------
Question 31
How many values can a variable contain at any time?
1
2
3
infinite number
| must include the address-of (&) operator before the array\'s name | ||
| must include the number symbol (#) before the array\'s name | ||
| do not have to do anything because arrays are automatically passed by reference |
Solution
1) To pass a one-dimensional array by reference, you do not have to do anything because arrays are automatically passed by reference.
For example :
#include <iostream>
float sum(float age[]);
int main() {
float s, age[] = { 23.4, 55, 22.6, 3, 40.5, 18 };
s = sum(age); /* Only name of array is passed as argument. */
printf(\"Sum of age=%.2f\", s);
return 0;
}
float sum(float age[])
{
int i;
float sum = 0.0;
for (i = 0; i < 6; ++i) {
sum += age[i];
}
return sum;
}
2) Assuming that the message variable contains the string \"Happy holidays\", the statement message.find(\"days\");
returns 10.
It returns the position where it finds the substring(the leftmost character position is numbered 0).
3) A field is a single item of information about a person, place, or thing.
4) How many values can a variable contain at any time? 1
At a time instance a primitive data type variable (like int, char) can store only one value. Arrays or other data structures can store more than one.

