Chapter 6 Programming

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

The special conversion specifier for printing addresses is __________. %a %m %p %loc

%p

The maximum number of comparisons needed for the binary search of a 2000 element array is 9 15 11 14

11

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

4-by-3 array

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

A static local variable exists for the duration of the program.

Which of the following statements is false? C provides automatic bounds checking for arrays. C provides no automatic bounds checking for arrays, so you must provide your own. Allowing programs to read from or write to array elements outside the bounds of arrays are common security flaws. 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.

C provides automatic bounds checking for arrays.

Which statement is true? Entire arrays are passed simulated call by reference and individual array elements are normally passed simulated call by reference. Entire arrays are passed simulated call by reference and individual array elements are normally passed call by value. Entire arrays are passed call by value and individual array elements are normally passed simulated call by reference. Entire arrays are passed call by value and individual array elements are normally passed call by value.

Entire arrays are passed simulated call by reference and individual array elements are normally passed simulated call by reference.

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

It is a high-performance sort.

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

It is initializing successive elements of an array.

Which statement is false? The brackets used to enclose the subscript of an array are not an operator in C. 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. The position number within an array is more formally called a subscript. "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.

The brackets used to enclose the subscript of an array are not an operator in C.

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

This statement increases the appropriate frequency counter depending on the value of responses[answer].

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

When using scanf, you must always precede with the & operator the name of each variable into which inputs are being placed.

An array is not ________. a consecutive group of memory locations indexed by integers pointer-based a dynamic entity

a dynamic entity

Unless otherwise specified, entire arrays are passed __________ and individual array elements are passed __________. call-by-value, call-by-reference call-by-reference, call-by-value call-by-value, call-by-value call-by-reference, call-by-reference

call-by-reference, call-by-value

Constant variables can be assigned values in executable statements do not have to be initialized when they are defined can be used to specify array sizes, thereby making programs more scalable can be used to specify array sizes, but this makes programs harder to understand

can be used to specify array sizes, thereby making programs more scalable

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

can result in changes to the value of an unrelated variable

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

char string1[] = {'f', 'i', 'r', 's', 't', '\0'};

Which definition tells the computer to reserve 12 elements for integer array c? c[12] int; int c [11]; c[11] int; int c[12];

int c[12];

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

int n[5] = {0, 7, 0, 3, 8, 2};

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

it knows the size of the array it was passed

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

the array parameter can be preceded by the const qualifier.


Kaugnay na mga set ng pag-aaral

Week 3 Quiz "Electricity" Units 26 & 28

View Set

Network + Chapter 8 Review Questions

View Set

9.7 - Methods of State Registration of Securities

View Set

Chapter 17 Plate Tectonics Quiz (Earth Science)

View Set

Chapter 12- Nervous System Physiology Homework

View Set

Protons, neutrons, electrons unit

View Set