Quiz8

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

8.3 Q1: The & operator can be applied to:

Answer: lvalues.

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

Answer: &t[ 3 ].

8.3 Q3: Three of the following expressions have the same value. Which of the following expressions has a value different from the others'?

Answer: *Ptr.

8.8 Q1: Which of the following can have a pointer as an operand?

Answer: ++.

8.8 Q2: 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?

Answer: 2012.

8.5 Q4: 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:

Answer: A constant pointer to constant data.

8.5 Q3: An array name is:

Answer: A constant pointer to nonconstant data.

8.6 Q2: To follow the principle of least privilege, the selectionSort function should receive the array to be sorted as:

Answer: A constant pointer to nonconstant data.

8.5 Q2: A function that prints a string by using pointer arithmetic such as ++ptr to output each character should have a parameter that is:

Answer: A nonconstant pointer to constant data.

8.5 Q1: A function that modifies an array by using pointer arithmetic such as ++ptr to process every value should have a parameter that is:

Answer: A nonconstant pointer to nonconstant data.

8.8 Q3: A pointer can not be assigned to:

Answer: A pointer of a type other than its own type and void without using the cast operator.

8.2 Q2: Pointers may be assigned to which of the following?

Answer: Both (b) and (c).

8.4 Q1: Which of the following is not a valid way to pass arguments to a function in C++?

Answer: By value with pointer arguments.

8.10 Q2: A string array is commonly used for:

Answer: Command-line arguments.

8.13.2 Q3: strtok does not:

Answer: Completely tokenize the string the first time it is called.

8.3 Q2: All of the following could cause a fatal execution-time error except:

Answer: Dereferencing a variable that is not a pointer.

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

Answer: Is a call to the function pointed to by max.

8.10 Q1: A string array:

Answer: Is actually an array of pointers.

8.9 Q2: Consider the following function: void reverse( char * string1, const char * string2 ) { int stringsize = sizeof( string1 )/sizeof( char ); *( string1 + stringsize -1 ) = '\0'; string1 = string1 + stringsize - 2; for ( ; *string2 != '\0'; string1--, string2++ ) *string1 = *string2; } What method does the function use to refer to array elements?

Answer: Pointer/offset notation.

8.2 Q1: Pointers cannot be used to:

Answer: Reference values directly.

8.7 Q1: sizeof:

Answer: Returns the total number of bytes in a variable.

8.13.1 Q1: Which of the following is not true?

Answer: String literals are written inside of single quotes.

8.13.2 Q2: Assuming that string1 = "hello" and string2 = "hello world", which of the following returns 0?

Answer: Strncmp( string1, string2, 5 );.

8.11 Q1: An algorithm that could execute for an unknown amount of time because it depends on random numbers may:

Answer: Suffer from indefinite postponement.

8.6 Q1: After the ith iteration of the selection sort:

Answer: The smallest i items of the array will be sorted into increasing order in the first i elements of the array.

8.12 Q1: Which of the following is not true of pointers to functions?

Answer: They can not be assigned to other function pointers.

8.8 Q4: Comparing pointers and performing pointer arithmetic on them is meaningless unless:

Answer: They point to elements of the same array.

8.2 Q3: What does the following declaration declare?int *countPtr, count;

Answer: Two pointers to ints.

8.13.1 Q2: cin.getline( superstring, 30 ); is equivalent to which of the following?

Answer: cin.getline( superstring, 30, '\n' );.

8.4 Q2: When a compiler encounters a function parameter for a single-subscripted array of the form int a[], it converts the parameter to:

Answer: int * a.

8.7 Q2: Which of the following gives the number of elements in the int array r[ ]?

Answer: sizeof r / sizeof ( int ).

8.13.2 Q1: Which of the following correctly copies the contents of string2 into string1? Assume that string2 is equal to "goodbye" and string1 is equal to "good morning"?

Answer: strcpy( string1, string2 );.


Set pelajaran terkait

Chapter 10-Accounting for Long-Term Liabilities Smartbook Assignment

View Set

Chapter 1 Exam FX completing application, underwriting, and delivering the policy.

View Set