CSE FINAL

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

5.15 The function prototype double mySqrt( int x ); (a) defines a function called mySqrt which takes an integer as an argument and returns a double (b) defines a function called double which calculates square roots (c) defines a function called mySqrt which takes an argument of type x and returns a double (d) defines a function called mySqrt which takes a double as an argument and returns an integer

ANS: (a)

5.27 A function prototype does not have to ________. (a) include parameter names (b) terminate with a semicolon (c) agree with the function definition (d) match with all calls to the function

ANS: (a)

6.11 Which of the following is not a correct way to initialize an array? (a) int n[ 5 ] = { 0, 7, 0, 3, 8, 2 }; (b) int n[] = { 0, 7, 0, 3, 8, 2 }; (c) int n[ 5 ] = { 7 }; (d) int n[ 5 ] = { 6, 6, 6 };

ANS: (a)

6.23 Which statement is true regarding the statement ++frequency[ responses[ answer ] ]; a) This statement increases the appropriate frequency counter depending on the value of responses[ answer ]. b) This statement increases the appropriate answer counter depending on the value of frequency[ responses ]. c) This statement increases the appropriate responses counter depending on the value of frequency[ answer ]. d) This statement produces a syntax error because subscripts cannot be nested.

ANS: (a)

6.32 To pass an array to a function, specify a) the name of the array without any brackets. b) the name of the array preceded by an empty pair of brackets. c) the name of the array followed by a pair of brackets including the size of the array. d) the name of the array followed by a pair of brackets including a number one less than the size of the array.

ANS: (a)

6.39 In order to calculate the __________ of an array of values, the array must be sort-ed. (a) median (b) mode (c) mean (d) (a), (b), and (c)

ANS: (a)

5.18 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 ) { return ( s * s * s ); } (c) double triple ( float n ) return ( 3 * n ); (d) double circumference ( int r ); return ( 3.14 * 2 * r );

ANS: (b)

5.51 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.52 Recursion is memory-intensive because ________. (a) it must occur numerous times before it terminates (b) previous function calls are still open when the function calls itself and the arguments of these previous calls still occupy space on the call stack (c) many copies of the function code are created (d) it requires large data values

ANS: (b)

5.9 If a = 7.0, b = 7.0 and c = 6.0, then what is printed by printf( "%.2f", sqrt( a + b * c ) ); a) 49 b) 7.00 c) 7 d) 49.00

ANS: (b)

6.15 Assume string1 is a character array. Which of the following operations does not produce a string? (a) string1[] = { 't', 'e', 's', 't', '\0' }; (b) string1[] = { 't', 'e', 's', 't' };

ANS: (b)

6.37 Which statement about the bubble sort is false? a) It is easy to program. b) It is a high-performance sort. c) It compares only adjacent elements with one another. d) The bubble sort compares successive pairs of elements.

ANS: (b)

6.41 Calculating which of the following normally requires the data to be sorted first a) mean b) median c) mode d) total

ANS: (b)

6.53 Which initialization is not performed by the following definition? int b[ 2 ][ 2 ] = { { 1 }, { 3, 4 } }; 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

ANS: (b)

5.10 What is the value of fabs( -5.0 )? a) 5 b) 5.0 c) -5 d) -5.0

ANS: (b) all math functions return double in C

5.19 int square( int ); is an example of a function __________. a) datatype b) stereotype c) prototype d) proceduretype

ANS: (c)

5.34 Which statement is true? a) When an argument is passed call by reference, a copy of the argument's value is made and passed to the called function. b) With call by reference, changes to the passed value do not affect the original variable's value in the calling functions. c) Call by value should be used whenever the called function does not need to modify the value of the caller's original value. d) Call by value should only be used with trusted called functions that need to modify the original variable.

ANS: (c)

5.37 In the expression n = a + rand() % b; (a) b is the shifting value (b) a is the scaling value (c) b is equal to the width of the desired range of integers (d) both (a) and (c)

ANS: (c)

5.50 A recursive function is a function that ________. (a) returns a double (b) takes 3 arguments (c) calls itself (d) is inside of another function

ANS: (c)

5.53 Which statement is false? a) A recursive function is a function that calls itself either directly or indirectly through another function. b) A recursive function knows how to solve only one or more base cases. c) The recursion step executes after the original call to the function terminates. d) In order for the recursion to eventually terminate, each time the function calls itself with a slightly simpler version of the original problem, this sequence of smaller and smaller problems must eventually converge on a base case.

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)

6.38 A bubble sort of 1000 elements requires a maximum of __________ passes. a) 1001 b) 1000 c) 999 d) 998

ANS: (c)

6.42 The __________ is the value that occurs most frequently in the data. a) mean b) median c) mode d) master

ANS: (c)

6.43 The binary search technique (a) is better suited to small arrays (b) is better suited to unsorted arrays (c) can only be used on a sorted array (d) is slower than a linear search

ANS: (c)

6.45 Which of these is generally thought of as a high-performance technique? a) bubble sort b) linear search c) binary search d) iteration

ANS: (c)

6.49 Given the following definitions, what is the value of b[ 1 ][ 0 ]? int b[ 2 ][ 2 ] = { { 1 }, { 3 , 4 } }; (a) 0 (b) 1 (c) 3 (d) this isn't a valid definition

ANS: (c)

6.7 The first element in every array is the __________ element. a) null b) 1 c) 0 d) empty

ANS: (c)

5.13 Which is not a motivation for "functionalizing" a program? a) The divide-and-conquer approach makes program development more manageable. b) Software reusability—using existing building blocks to create new programs. c) Avoid repeating code. d) Execution performance—functionalized programs run faster.

ANS: (d)

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

ANS: (d)

5.38 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.57 All of the following are reasons to use recursion except: (a) an iterative solution is not apparent (b) the resulting program is easier to debug (c) it more naturally mirrors the problem (d) it maximizes software performance

ANS: (d)

6.10 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.16 Suppose a program contains the code for (i = 1; i < = 10; i++) n[ i ] = 0; Which statement about this code must be true? a) b) It contains a syntax error. b) It is initializing the first 10 elements of an array. c) It is initializing successive elements of an array.

ANS: (d)

6.17 What's wrong with this code? int n[] = ( 1, 2, 3, 4, 5); a) The array size must be specified in the square brackets. b) The parentheses should be square brackets. c) The square brackets should be curly braces. d) The parentheses should be curly braces.

ANS: (d)

6.29 Unless otherwise specified, entire arrays are passed __________ and individual array elements are passed __________.

ANS: reference

6.19 T or False? a) Arrays are automatically initialized to zero. b) To initialize all array elements to zeros, the array definition must explicitly initialize each element to zero. c) Array elements can be initialized to zero by the array definition only at compile time.

F F F

6.33 Read Following statements T/F ? a) C automatically passes arrays to functions using pass by reference. b) When C passes an array to a function, the called function normally can modify the element values in the caller's original array. c) The name of an array is actually the address of the first element of the array.

_ T T

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

ANS: (b)

5.35 The rand function generates a data value of the type (a) unsigned int (b) int (c) long int (d) short int

ANS: (b)

5.21 The type of a parameter whose type is omitted in a function definition is __________. a) int b) double c) long d) float

ANS: (a)

6.40 The _____ is the average value of a set of data items. a) mean b) median c) mode d) matrix

ANS: (a)

6.20 The following array definition int n[ 5 ] = { 32, 27, 64, 18, 95, 14 }; a) is correct b) causes a syntax error because there are only five initializers and six array elements. c) causes a logic error because there are only five elements but there are six initializers. d) causes a syntax error because there are six initializers but only five array elements.

ANS: (d)

6.26 The definition char string1[] = "first"; is equivalent to: a) character string1[] = { 'f', 'i', 'r', 's', 't', '\0' }; b) char string1 = { 'f', 'i', 'r', 's', 't', '\0' }; c) char string1[] = { 'f', 'i', 'r', 's', 't' }; d) char string1[] = { 'f', 'i', 'r', 's', 't', '\0' };

ANS: (d)

6.5 Which of the following is false? (a) the first element of an array is the zeroth (b) the last element of an array is the array size - 1 (c) the position number contained within square brackets is called a subscript (d) a subscript cannot be a VARIABLE.

ANS: (d)

6.52 An array containing 3 columns and 4 rows is typically referred to as a __________. Depends on the terminology you are used to!! People look at 2D arrays as matrix a) 12-element array b) 3-by-4 array c) 13-element array, because of the zero element d) 4-by-3 array

ANS: (d)

6.6 An array is a group of memory locations related by the fact that they all have __________ array name and __________ type. a) different, different b) same, different c) different same d) same, same

ANS: (d)

6.9 Which statement would be used to define a 10 element integer array c? (a) Array c = int[ 10 ]; (b) c = int[ 10 ]; (c) int Array c[ 10 ]; (d) int c[ 10 ];

ANS: (d)

6.50 following will initialize all of the array elements to 0? a) int b[ 2 ][ 2 ] = { 0 }; T/F b) int b[ 2 ][ 2 ]; T/F for ( int i = 0; i < 2; ++i ) for (int j = 0; j < 2; ++j ) b[ i ][ j ] = 0;

T T

6.46 true/false? a) The linear searching method works well for small arrays. b) The linear searching method works well for unsorted arrays. c) The binary search algorithm eliminates from consideration one half of the elements in a sorted array after each comparison.

T T T


संबंधित स्टडी सेट्स

A.Škėmos romano "Balta drobulė" apibendrinimas

View Set

AP G&P - The relationship between the states and the federal government

View Set

Virology Midterm (Quizzes & Self Assessments)

View Set

Shoulder Joint Muscles (Origin/Insertion/Action)

View Set