Professional Documents
Culture Documents
Test Bank For C Programming From Problem Analysis To Program Design 6th Edition D S Malik
Test Bank For C Programming From Problem Analysis To Program Design 6th Edition D S Malik
TRUE/FALSE
1. Using functions greatly enhances a program’s readability because it reduces the complexity of the
function main.
2. Once you write and properly debug a function, you can use it in the program (or different programs)
again and again without having to rewrite the same code repeatedly.
3. If the formal parameter list of a function is empty, the parentheses after the function name are not
needed.
5. The data type of a variable in a return statement must match the function type.
7. In C++, a function prototype is the function heading without the body of the function.
8. Assume that all variables are properly declared. The following statement in a value-returning function
is legal.
if (x % 2 == 0)
return x;
else
return x + 1;
MULTIPLE CHOICE
2. To use the predefined function tolower, the program must include the header file ____.
a. <cctype> c. <cmath>
b. <iostream> d. <cstdlib>
ANS: A PTS: 1 REF: 338
is ____.
a. '$'
b. '0'
c. '1'
d. An error, because you cannot use tolower with '$'.
ANS: A PTS: 1 REF: 338
static_cast<int>('a') = 97
static_cast<int>('A') = 65
5. The output of the statement: cout << pow(3.0, 2.0) + 5 << endl; is ____.
a. 11.0 c. 13.0
b. 12.0 d. 14.0
ANS: D PTS: 1 REF: 338
is ____.
a. 6.0 c. 8.0
b. 7.0 d. 9.0
ANS: C PTS: 1 REF: 338
7. Functions that do not have a return type are called ____ functions.
a. zero c. void
b. null d. empty
ANS: C PTS: 1 REF: 341
int next(int x)
{
return (x + 1);
}
a. 5 c. 7
b. 6 d. 8
ANS: C PTS: 1 REF: 347-348
15. Given the following function prototype: double tryMe(double, double);, which of the
following statements is valid? Assume that all variables are properly declared.
a. cin >> tryMe(x);
b. cout << tryMe(2.0, 3.0);
c. cout << tryMe(tryMe(double, double), double);
d. cout << tryMe(tryMe(float, float), float);
ANS: B PTS: 1 REF: 349-350
16. Given the function prototype: double testAlpha(int u, char v, double t); which of
the following statements is legal?
a. cout << testAlpha(5, 'A', 2);
b. cout << testAlpha( int 5, char 'A', int 2);
c. cout << testAlpha('5.0', 'A', '2.0');
d. cout << testAlpha(5.0, "65", 2.0);
ANS: A PTS: 1 REF: 349-350
20. Given the following function prototype: int myFunc(int, int);, which of the following
statements is valid? Assume that all variables are properly declared.
a. cin >> myFunc(y);
b. cout << myFunc(myFunc(7, 8), 15);
c. cin >> myFunc('2', '3');
d. cout << myFunc(myFunc(7), 15);
ANS: B PTS: 1 REF: 349-350
a. -1 c. 9
b. 1 d. 20
ANS: A PTS: 1 REF: 351
int x = 5;
return x + 1;
a. 0 c. 6
b. 5 d. 7
ANS: C PTS: 1 REF: 351
COMPLETION
1. A(n) ____________________ parameter s a formal parameter that receives a copy of the content of
the corresponding actual parameter.
ANS: value
2. When you attach & after the dataType in the formal parameter list of a function, the variable
following that dataType becomes a(n) ____________________ parameter.
ANS: reference
3. A(n) ____________________ parameter is a formal parameter that receives the location (memory
address) of the corresponding actual parameter.
ANS: reference
ANS:
Reference
reference
5. If a formal parameter is a nonconstant reference parameter, during a function call, its corresponding
actual parameter must be a(n) ____________________.
ANS: variable
ANS: scope
8. If a function needs to return more than one value, as a rule of good programming style, you should
change it to a(n) ____________________ function and use the appropriate reference parameters to
return the values.
ANS: void
ANS: Local
11. A variable for which memory is allocated at block entry and deallocated at block exit is called a(n)
____________________ variable.
ANS: automatic
12. A variable for which memory remains allocated as long as the program executes is called a(n)
____________________ variable.
ANS: static
13. The program that tests a function is called a(n) ____________________ program.
ANS: driver
ANS: stub
15. The ____________________ of a function consists of the function name and its formal parameter list.
ANS: signature