Multiple Choice Homework for Quiz4

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

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

a

A dimensioned array is not ________. (a) a consecutive group of memory locations (b) subscripted by integers (c) pointer-based (d) a dynamic entity

d

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) 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

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, 7, 8 };

a

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 ];

d

An array containing 3 columns and 4 rows is typically referred to as a __________. (a) 12-element array (b) 3-by-4 array (c) 13-element array, because of the zero element (d) 4-by-3 array

d

An array dimensioned as x[100] is a __________ entity in that they remain the same size throughout program execution. (a) dynamic (b) automatic (c) register (d) static

d

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

d

Assuming myString is a 20-element char array, which of the following statements might result in buffer overflow? (a) scanf( "%19s", myString ); (b) scanf_s( "%s", myString, 20 ); (scanf_s Microsoft specific specifies length of buffer) (c) scanf_s( "%19s", myString, 20 ); (d) scanf( "%s", myString );

d

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

d

If the initializing sequence is shorter than an array, then the rest of the values are initialized to zero.

True

A double-subscripted array element incorrectly referenced as a[ x, y ] is actually evaluated as (a) a[ x ][ y ] (b) a[ y ] (c) a[ x ] (d) a[ 0 ]

a

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

b

Strings can not (a) be initialized using string literals (i.e. words in "double quotes") (b) end in a character other than the null character (c) be initialized with initializer lists (e.g. char str[20] = { 'h', 'e', 'l', 'l', 'o', '\0' }; ) (d) be treated as arrays of characters

b

The following code will? sum = 0; for (row=0; row<N_ROW; row++)sum += table[row][2]; (a) sum the values of row 2. (b) sum the values of column 2. (c) sum the values of row N_ROW. (d) none of the above.

b

A sorted array of a million elements can be searched by a binary search in __________ or fewer comparisons. (a) 10 (b) 20 (c) 30 (d) 999,999

20

All values of an array are printed if we specify the identifier of the array without subscripts.

False

If an array is defined without a size, but with an initialization sequence, then the array size is arbitrary.

False

When the value of a subscript or index is greater than the largest valid subscript of an array, it will always cause an execution error.

False

An array is (a) a group of values that all have a common variable name and all have the same data type. (b) a collection of elements of different data types that are stored in adjacent memory locations. (c) a single variable location that contains multiple values of the same data type. (d) a location in memory that holds multiple values of the same data type.

a

An individual element in the array is addressed by specifying (a) the name of the array and the number of the element. (b) the name of the array. (c) the number of the element within the array followed by the name of the array. (d) the number of the element in the array

a

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

a

Referencing elements outside the array bounds (a) can result in changes to the value of an unrelated variable (b) is impossible because C checks to make sure it does not happen (c) is a syntax error (d) enlarges the size of the array

a

The subscript identifies the ________ of a particular element in the array. (a) location (b) value (c) range (d) name

a

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.

a

Which of the following is false about a function being passed an array? (a) it knows the size of the array it was passed (b) it is passed the address of the first element in the array (c) it is able to modify the values stored in the array (d) all of the above are true

a

Which of the following statements is false? (a) C provides automatic bounds checking for arrays. (b) C provides no automatic bounds checking for arrays, so you must provide your own. (c) Allowing programs to read from or write to array elements outside the bounds of arrays are common security flaws. (d) Writing to an out-of-bounds element (known as a buffer overflow) can corrupt a program's data in memory, crash a program and allow attackers to exploit the system and execute their own code.

a

Which statement is false? (a) The brackets used to enclose the subscript of an array are not an operator in C. (b) To refer to a particular element in an array, we specify the name of the array and the position number of the element in the array. (c) The position number within an array is more formally called a subscript. (d) "Array element seven" and the "seventh element of an array" do not mean the same thing. This is a frequent source of off-by-one errors.

a

Which statement is true regarding the statement ++frequency[ responses[ answer ] ]; (this is an array of counters) (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.

a

Which statement is true? (note a symbolic constant is created with #define) (a) Assigning a value to a symbolic constant in an executable statement is a syntax error (b) A symbolic constant is a variable. (c) Space is reserved for both symbolic constants and variables that hold values at execution time (d) Only uppercase letters can be used for symbolic constant names.

a

To prevent modification of array values in a function, (a) the array must be defined static in the function. (b) the array parameter can be preceded by the const qualifier. (c) a copy of the array must be made inside the function. (d) the array must be passed call-by-reference.

b

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

b

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

b

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.

b

Which statement is false? (a) A static local variable exists for the duration of the program. (b) A static local variable is visible only in the control structure in which it is defined. (c) A static local array is not created and destroyed each time the function is entered and exited, respectively. (d) Arrays that are defined static are automatically initialized once at compile time.

b

Which statement is true? (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. (d) Definitions for automatic arrays initialize the arrays at execution time

b

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

c

Arrays are data structures consisting of related data items of the same __________. (a) sort order (b) subscript (c) type (d) element

c

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

c

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

c

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

c

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

c

The maximum number of comparisons needed for the binary search of a 2000 element array is (a) 9 (b) 15 (c) 11 (d) 14

c

The special conversion specifier for printing addresses is __________. (a) %a (b) %m (c) %p (d) %loc

c

What is true of Constant definitions (a) can be assigned values in executable statements (b) do not have to be initialized when they are defined (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

c

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

c

Which statement is false? (a) C has no built-in bounds checking to prevent the computer from referring to an array element that does not exist. (b) The programmer is responsible for implementing array bounds checking. (c) Referring to an element outside the array bounds is a syntax error. (d) Referring to an element outside the array bounds is a logic error.

c

Which statement is true? (a) A symbolic constant is an identifier that is replaced with replacement text (could be a number) by the C preprocessor after the program is compiled. (b) Using symbolic constants to specify array sizes makes programs run faster. (c) Preprocessor directives are not C statements. (d) The #define preprocessor directive must end in a semicolon.

c

Suppose a program contains the code for (i = 1; i < = 10; i++) n[ i ] = 0; Which statement about this code must be true? (a) It contains an off-by-one error. (b) It contains a syntax error. (c) It is initializing the first 10 elements of an array. (d) It is initializing successive elements of an array.

d

The definitionchar 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' };

d

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.

d

What's wrong with this code? int[] = ( 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.

d

Which definition tells the computer to reserve 12 elements for integer array c? (a) malloc int c[ 12 ]; (b) reserve c [ 11 ]; (c) int c[ 11 ]; (d) int c[ 12 ];

d

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 (also index) (d) a subscript cannot be an expression.

d

Which of the following statements is 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. d) The binary search terminates only when the search key is equal to the middle element of a subarray.

d

Which statement about bubble sort is true? (a) a maximum of n passes are needed to sort the array, where n is the number of elements (b) swapping values requires two assignments (c) performance is maximized (d) the algorithm is very simple compared to other sorting procedures

d

Which statement is false about multiple-subscripted arrays? (a) C supports multiple-subscripted arrays. (b) A common use of multiple-subscripted arrays is to arrange data into tables consisting of rows and columns. (c) To identify a particular table element requires two subscripts. (d) Every ANSI C system can support arrays with as many subscripts as the programmer chooses.

d

Which statement is false? (a) C automatically passes arrays to functions using implied call 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. (d) When an array is passed in a function call, the calling function knows precisely where in the called function's memory the passed array is.

d

Which statement is false? (a) Function scanf reads characters into memory from the keyboard until the first input whitespace character is encountered. (b) Function scanf can write beyond the boundary of the array into which input is being placed. (c) Function printf does not care how large the array it is printing is. (d) When using scanf, you must always precede with the & operator the name of each variable into which inputs are being placed.

d

Which statement is false? (a) The string termination character is called the null character. (b) The string "string" actually occupies 7 characters in memory. (string + \0 esc sequence) (c) The character representation of the last character in memory of a string is '\0'. (d) A character array representing a string should be defined as large as the actual number of characters in the string minus the terminating character; C automatically provides the space for the terminating character.

d


Kaugnay na mga set ng pag-aaral

Chapter 17 Investing in Real Estate and Other Investment Alternatives

View Set

Identities: One solution, no solution, or infinitely many solutions?

View Set

Spanish 2 Ch.1B TestPrep Realidades2...

View Set

Suffixes For Diagnostic, Medical, & Surgical Procedures

View Set

Inv - Insurance based products (3)

View Set

Psychiatric-Mental Health Nursing Varcarolis Ch. 9

View Set