Chapter 5 & 6
Chapter 5 & 6
Chapter 5 & 6
1 Intro d u c tio n
5.2 Pro gr a m M o d ul e s in C
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
ANS: (c)
5.4. Which one item is most different from the other three?
a) worker function
b) caller
c) calling function
d) boss function
ANS: (a)
d) inverted #(77
ANS: (b)
5.3 M a th Li br a ry Fu n c tio ns
5.9. All functions in the math library return the data type __________.
a) float
b) int
c) long
d) double
ANS: (d)
5.10. What happens when you do not include math.h when using functions in
the math library?
a) compilation error
b) execution error
c) logic error
d) strange results may occur
ANS: (d)
5.4 Fu n c tio ns
5.19 Using the following function definition, the return value type is
represented by
A B( C ) {
D
}
(a) A
(b) B
(c) C
(d) D
ANS: (a)
5.22 Which of the following functions 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 );
return ( 5.14 * 2 * r );
ANS: (c)
5.24. As used in
int square( int );
int is not a(n) __________.
a) data type
b) parameter type
c) return type
d) function prototype
ANS: (d)
5.27. The most concise notation to use to define function parameters x and y
as double is __________.
a) x, y
b) x, double y
c) double x, y
d) double x, double y
ANS: (d)
5.7 H e a d e r Fil e s
5.36 Each standard library has a corresponding __________.
(a) function
(b) variable type
(c) header file
(d) cd-rom
ANS: (c)
5.37. Which standard library header file contains function prototypes for
conversions of numbers to text and text to numbers, memory allocation,
random numbers and other utility functions.
a) <stdarg.h>
b) <stdlib.h>
c) <stdutl.h>
d) <stddef.h>
ANS: (b)
5.9 R a n d o m N u m b e r G e n e r a tio n
5.40 The rand function generates a data value of the type
(a) unsigned int 0- 65535
(b) int
(c) long int
(d) short int
ANS: (a)
5.41 A variable that can only have values in the range 0 to 65535 is a
(a) four-byte int 2
b
65536
=
5.43 srand
(a) should be called before each call to rand
(b) should be used instead of rand to generate truly random numbers
(c) is unnecessary in C
(d) can use time as an automatically input seed value
ANS: (d)
5.10 Ex a m p l e : A G a m e o f C h a n c e
5.11 St or a g e C l a sse s
變數名稱
5.45 An identifier’s storage class
(a) determines the period during which that identifier exists in memory
(b) determines whether an identifier is known only in the current source file
or in any source file with proper definitions
(c) determines where the identifier can be referenced in a program
(d) all of the above
ANS: (a)
特徵
5.48. Which is not an attribute of a variable
a) name
b) definition
c) type
d) value
ANS: (b)
5.52. Global variables and function names are of storage class __________
by default.
a) register
b) extern
c) static
d) auto
ANS: (b)
5.12 S c o p e Rul e s
5.54 The only identifiers that can be reused elsewhere in a program without
any ambiguity are
(a) global variables
(b) static local variables
(c) those in the parameter list of a function prototype
(d) those in the parameter list of a function definition
ANS: (c)
5.55. Which statement is false?
a) When we define a local variable in a block it can be referenced only in
that block or in blocks in which that block is nested.
b) Labels are the only identifiers with function scope.
c) Labels can be used anywhere in the function in which they appear, but
can not be referenced outside the function body.
d) Labels are used in switch statements and in goto statements.
ANS: (a)
5.13 R e c ursio n
5.58 What value does function mystery return when called with a value of
4?
int mystery ( int number ) {
if ( number <= 1 )
return 1;
else
return number * mystery( number – 1 );
}
(a) 1
(b) 24
(c) 0
(d) 4
ANS: (b)
5.61 Assuming the following pseudocode for the fibonacci series, what is
the value of the 5th fibinacci number? f(4)
fibbonacci( 0 ) = 0
fibonacci( 1 ) = 1
fibonacci( n ) = fibonacci( n – 1 ) + fibonacci( n – 2 )
(a) 0
(b) 1
(c) 3
(d) 5
ANS: (c)
6.1. Arrays are data structures consisting of related data items of the same
__________.
a) sort order
b) subscript
c) type
d) element
ANS: (c)
IEEETr
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
ANS: (d)
6.3. Lists, queues, stacks and trees are __________ data structures that may
grow and shrink as programs execute.
a) flexible
b) automatic
c) dynamic
d) static
ANS: (c)
6.2 Arr a ys
6.5 Assuming that int a has a value of 3 and that integer array b has 7
elements, what is the correct way to assign the value of the sum of 3 and the
third element, to the fifth element of the array?
(a) b[ a + 1 ] = b[ a ] + 3;
(b) b[ a + 1 ] = b[ a - 1 ] + 3;
L
(c) b[ a ] + 1 = b[ a + 3];
(d) b[ a + 2 ] = b[ a ] + 3;
ANS: (b)
6.7. An array is a group of memory locations related by the fact that they all
have __________ name and __________ type.
a) different, different
b) same, different
c) different same
d) same, same
ANS: (d)
6.11. Which definition tells the computer to reserve 12 elements for integer
array c?
a) c[ 12 ] int;
b) int c [ 11 ];
c) c[ 11 ] int;
d) int c[ 12 ];
ANS: (d)
6.43. The __________ is the value that occurs most frequently in the data.
a) mean
b) median
c) mode
d) master
ANS: (c)
6.45 The maximum number of comparisons needed for the binary search of
a 2000 element array is
(a) 9 2"= 2048 < 2000 2"= 1024
(b) 15
(c) 11
(d) 14
ANS: (c)
b) 20
=
c) 30
d) 999,999
ANS: (b)
6.51 Which of the following does not initialize all of its elements to 0?
(a) int b[ 2 ][ 2 ];
b[ 0 ][ 0 ] = b[ 0 ][ 1 ] = b[ 1 ][ 0 ] = b[ 1 ][ 1 ];
(b) int b[ 2 ][ 2 ] = { 0 };
(c) 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.
ANS: (d)