Chapter 6 - Chapter 8

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

The special conversion specifier for printing addresses is______________

%p

Pointers cannot be used to (a) find the address of a variable in memory. (b) reference values directly. (c) simulate call-by-reference. (d) manipulate dynamic data structures.

(b) reference values directly.

Pointers may be assigned which of the following? (a) all integer values (b) an address (c) NULL (d) both (b) and (c)

(d) both (b) and (c)

A sorted array of a million elements can be searched by a binary search in_________ or fewer comparisons.

20

Given that k is an integer array starting at location 2000, kPtr is a pointer to k and each integer is stored in 4 bytes of memory, what location does kPtr + 3 point to?

2012

Which of the following can have a pointer as an operand? A) ++ B) *= C) % D) /

A) ++

The unary * and __________ are complements of one another. A) / B) ^ C) & D) |

C) &

A two-dimensional array element incorrectly referenced as a[x, y] is actually evaluated as

a[y]

Pointers are variables that contain __________ as their values. a) strings b) flowlines c) memory addresses d) directions

c) memory addresses

The binary search technique

can only be used on a sorted array

Which statement about pointers is false? a) A pointer with the value NULL points to nothing. b) NULL is a symbolic constant defined in the <stdio.h> header file. c) Initializing a pointer to 0 is equivalent to initializing a pointer to NULL, but NULL is preferred. d) The values 0 and 1 are the only values that can be assigned directly to a pointer variable.

d) The values 0 and 1 are the only values that can be assigned directly to a pointer variable.

The definition int *count; a) is a syntax error because only pointers can be defined with * notation. b) is a compile-time error. c) is a logic error. d) is a correct definition of integer pointer count.

d) is a correct definition of integer pointer count.

Which function does not read data from standard input?

sprintf

Assuming that t is an array and tPtr is a pointer to that array, which expression refers to the address of element 3 of the array?

&t[ 3 ]

The first element in every array is the ________ element.

0

Given the following definitions, what is thevalue of b[1][0]?int b[2][2] = {{1}, {3, 4}};

3

An array containing 3 columns and 4 rows is typically referred to as a __________.

4-by-3 array

A bubble sort of 1000 elements requires a maximum of _______ passes.

999

Which statement is false about multidimensional arrays?

A common use of multidimensional arrays is to arrange data into tables consisting of rows and columns.

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 is visible only in the control structure in which it is defined

Which of the following statements is false? A) A key feature of functions like printf_s and scanf_s that makes them more secure is that they have runtime pointer constraints that are checked after attempting to use the pointers B) In a scanf_s, if any of the pointer arguments (including the format-control string) are NULL, the function returns EOF. C) In a printf_s, if the format-control string or any argument that corresponds to a %s is NULL, the function stops outputting data and returns a negative number. D) None of the above.

A) A key feature of functions like printf_s and scanf_s that makes them more secure is that they have runtime pointer constraints that are checked after attempting to use the pointers

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) C provides automatic bounds checking for arrays.

Which statement is false? A) Function strcpy copies its first argument into its second argument. B) Function strncpy does not necessarily copy the terminating null character of its second argument. C) A common error is not appending a terminating null character to the first argument of a strncpy when the third argument is less than or equal to the length of the string in the second argument. D) The first character of the second argument of strcat replaces the null character that terminates the string in the first argument.

A) Function strcpy copies its first argument into its second argument

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) 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]]; 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) This statement increases the appropriate frequency counter depending on the value of responses[answer].

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) can result in changes to the value of an unrelated variable

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

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

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) it knows the size of the array it was passed

Which statement is true? A) strtok modifies the input string. B) strtok makes a backup copy of the input string. C) The first argument of each call to strtok is the string being tokenized. D) strtok works only with a set of four predefined delimiters.

A) strtok modifies the input string.

Three of the follow expressions have the same value. Which of the following expressions has a value different from the others'? A)*ptr B)&*ptr C)ptr D)*&ptr

A)*ptr

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)

B) A Static Local Variable is visible only in the control structure in which it is defined.

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) It is a high-performance sort.

Which statement about pointers is false? A) They can be defined to point to objects of any data type. B) The indirection operator * distributes to all comma-separated variable names in a definition. C) The letters Ptr in a pointer variable name are optional. D) A pointer may be initialized to 0, NULL or an address.

B) The indirection operator * distributes to all comma-separated variable names in a definition.

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) call-by-reference, call-by-value

Pointers cannot be used to A) find the address of a variable in memory. B) reference values directly. C) simulate call-by-reference. D) manipulate dynamic data structures

B) reference values directly.

Function _________ takes an error number and creates and error message string. A) errorstr B) strerror C) badstr D) strfail

B) strerror

Which of the following does not necessarily append the null character to its result? A) strcpy B) strncpy C) strcat D) strncat

B) strncpy

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. the array must be passed call-by-reference.

B) the array parameter can be preceded by the const qualifier.

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

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

Which of these is generally thought of as a high-performance technique?

Binary search

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

Which statement is false? A) The operand of the address operator must be a variable. B) The address operator cannot be applied to constants or to expressions. C) The address operator can be applied to variables defined with the storage class register. D) The address operator can be applied to variables defined with the storage class static

C) The address operator can be applied to variables defined with the storage class register.

Constant variables 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) can be used to specify array sizes, thereby making programs more scalable

What memory function of the string handling library copies an unsigned char into a specified number of the leading locations pointed by its first argument? A) memcpy B) memmove C) memset D) memlead

C) memset

strtok does not A) replace each delimiting character with '\0' B) return a pointer to the token it creates C) tokenize the entire a string when it's called D) modify the input string

C) tokenize the entire string when it's called

The & operator can be applied to A) constants B) variables defined with the storage class register C) variables defined with the storage class static D) rvalues

C) variables defined with the storage class static

The special conversion specifier for printing addresses is __________. A) %a B) %m C)%p D) %loc

C)%p

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) 4-by-3 array

What method should be used to pass an array to a function that does not modify the array and only looks at it using array subscript notation: A) A nonconstant pointer to nonconstant data. B) A nonconstant pointer to constant data. C) A constant pointer to nonconstant data. D) A constant pointer to constant data.

D) A constant pointer to constant data.

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) It is initializing successive elements of an array.

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) 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) a consecutive group of memory locations B) indexed by integers C) pointer-based D) a dynamic entity

D) a dynamic entity

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

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

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

D) int c[12];

The definition int *count; A) is a syntax error because only pointers can be defined with * notation. B) is a compile-time error. C) is a logic error. D) is a correct definition of integer pointer count.

D) is a correct definition of integer pointer count.

The integral type of the value returned by operator sizeof is ________. A) size-t B) sizet C) size.t D) size_t

D) size_t

A pointer to a function contains __________. A) the address of the function's automatic variables B) the address of the function on the stack C) the address of the entry for that function in the System Function Table D) the address of the function in memory

D) the address of the function in memory

Lists, queues, stacks and trees are _________ data structures that may grow and shrink as programs execute.

Dynamic

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 call by value.

( *max )( num1, num2, num3 ); :

Is a call to the function pointed to by max.

Which statement about the algorithm we presented in Section 7.10 of the text for shuffling a deck of cards is true?

It could execute indefinitely

Which statement is false?

Structures are always passed call by reference.

An algorithm that could execute for an unknown amount of time because it depends on random numbers to exit a function may

Suffer from indefinite postponement.

Which statement about function memcpy is false?

The result of this function is defined even if the two objects overlap in memory.

Which statement is false?

When applied to the name of an array, sizeof returns the number of elements in the array.

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.

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

Which statement about pointers is false? a) They can be defined to point to objects of any data type. b) The indirection operator * distributes to all comma-separated variable names in a definition. c) The letters Ptr in a pointer variable name are optional .d) A pointer may be initialized to 0, NULL or an address.

b) The indirection operator * distributes to all comma-separated variable names in a definition.

A non-pointer variable name __________ references a value and a pointer variable name __________ references a value. a) directly, directly b) directly, indirectly c) indirectly, directly d) indirectly, indirectly

b) directly, indirectly

Referencing a value through a pointer is called __________. a) interdiction b) indirection c) intermediation d) redirection

b) indirection

Which initialization is not performed by the following definition?int b[2][2] = {{1},{3,4}};

b[0[1] is set to 1

The following array definitionint n[5] = {32, 27, 64, 18, 95, 14};

causes a logic a syntax error because there are six initializer but only five array elements.

the definition char string1[]="first"; is equivalent to:

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

The strtol and stroul functions do not ________.

have to convert the entire string they are given.

If there are fewer initializers than elements in the array, the remaining elements are ___________.

initialized to zero

A character constant is a(n) _______ value represented as a character in single quotes?

int

Which of the following does not initialize all of the array elements of 0?

int b[2][2]; for (int I= 0; I <2; ++I){ for (int j = 0; j < 2;++j){ b[I][j] = 0 } }

Which definition tells the computer to reserve 12 elements for integer array c?

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

The functions of the character handling library typically manipulates characters as _______?

ints.

Which character handling library function returns true it its argument is a printing character?

isprint

Suppose a program contains the code ( = 1; I <= 10; I++){ n[I] = 0 } which statement about this code must be true?

it is initializing successive elements of an array.

the____ is the average value of a set of data items.

mean

In order to calculate the ___________ of an array the array must be sorted.

median

The ________ function allows characters of one part of a string to be copied into another part of the string.

memmove

A function that prints a string should have a parameter that's a

nonconstant pointer to constant data

When the computer compares two strings, it actually compares the ________ in the strings.

numeric code of the characters

when a structure must be passed to a function, we can use pointers to constant data to get the performance of a call by _________________ and the protection of a call by _________________.

reference, value

An array is a group of memory locations related by the fact that they all have _________ array name and ______________type.

same, same

Assuming myString is a 20-element char array, which of the following statements might result in buffer overflow?

scanf("%s", myString);

Function strcmp returns ______ if its first argument is equal to its second argument.

specifically 0

Arrays and structures are ____________ entities in that they remain the same size throughout program execution

static

The general utilities library is

stdlib

Function _______ searches for the first occurrence of a character in a string.

strchr

Assume string1 is a character array. Which of the following operations does not produce a string?

string1[]={'t', 'e', 's', 't'};

Function ________ compares up to n characters of its first argument with its second argument.

strncmp

Assuming that string1 = "Hello" and string2 = "Hello World", Which of the following returns 0?

strncmp(string1, string2, 5);

To prevent modification of array values in a function,

the array parameter can be preceded by the const qualifier.

To pass an array to a function, specify

the name of the array without any brackets

what is wrong with this code?int[]=(1,2,3,4,5);

the parentheses should be curly braces.

Arrays are data structures consisting of related data items of the same _____________.

type


Kaugnay na mga set ng pag-aaral

Prep U: Chapter 30: Management of Patients with Hematologic Neoplasms

View Set

HROD Chapter 8 MC - Power and Politics

View Set

Autonomic Nervous system Anatomy Lecture

View Set

Service Benefit Package - Travel

View Set

Antepartum, Reproduction and Sexuality Unit #3

View Set