Professional Documents
Culture Documents
Progress Test 02
Progress Test 02
Functions
5.1 All of the following are true of functions except:
(a) they define specific tasks that can be used at many points in a
program
(b) a function call must specify the name and arguments of the
function
(c) the definition of a function is always visible to other functions
(d) the implementation of a function is hidden from the caller
5.2 Experience has shown that the best way to construct a program is
from small pieces. This is called __________.
a) bottom up
b) the whole is greater than the sum of the parts
c) divide and conquer
d) recursion
5.4 Which one item is most different from the other three?
a) worker function
b) caller
c) calling function
d) boss function
5.8 All functions in the math library return the data type __________.
a) float
b) int
c) long
d) double
(b) floor
(c) ln
(d) log10
5.18 Which of the following code segments does not contain any
errors?
(a)
void printnum (int x)
{
print("%i", x);
return x;
}
(b)
int cube(int s)
{
int s;
return (s * s * s);
}
(c)
double triple(float n) {
return (3 * n);
}
(d)
double circumference (int r)
IPC144 Progress Test #02
5.20 As used in
int square(int);
int is not a(n) __________.
a) data type
b) parameter type
c) return type
d) function prototype
5.33 When arguments are passed by __________, the caller allows the
called function to modify the original variable’s value.
(a) value
(b) reference
(c) both a and b
(d) none of these
IPC144 Progress Test #02
5.51 What value does function mystery return when called with a
value of 4?
int mystery (int number)
{
if (number <= 1) {
return 1;
IPC144 Progress Test #02
}
else {
return number * mystery(number – 1);
}
}
(a) 1
(b) 24
(c) 0
(d) 4
Arrays
6.1 Arrays are data structures consisting of related data items of the
same __________.
a) sort order
b) subscript
c) type
d) element
6.2 Arrays and structures are __________ entities in that they remain the
same size throughout program execution.
a) dynamic
b) automatic
c) register
d) static
d) same, same
(c) can be used to specify array sizes, thereby making programs more
scalable
(d) can be used to specify array sizes, but this makes programs harder
to understand
6.18 If there are fewer initializers than elements in the array, the
remaining elements are __________.
a) deleted
b) ignored
c) initialized to empty
d) initialized to zero
character.
6.29 Unless otherwise specified, entire arrays are passed __________ and
individual array elements are passed __________.
(a) call-by-value, call-by-reference
(b) call-by-reference, call-by-value
(c) call-by-value, call-by-value
(d) call-by-reference, call-by-reference
6.50 Which of the following does not initialize all of the array
elements to 0?
(a)
int b[2][2];
b[0][0] = b[0][1] = b[1][0] = b[1][1] = 0;
(b) int b[2][2] = {0};
(c)
IPC144 Progress Test #02
int b[2][2];
for (int i = 0; i < 2; ++i) {
for (int j = 0; j < 2; ++j) {
b[i][j] = 0;
}
}
(d) all of the above initialize all of their elements to 0.
a)b[0][0] is set to 1
b) b[0][1] is set to 1
c) b[1][0] is set to 3
d) b[1][1] is set to 4