CRC CISP 400 C++ Quiz 4
An array name is: 1. A constant pointer to nonconstant data. 2. A nonconstant pointer to constant data. 3. A nonconstant pointer to nonconstant data. 4. A constant pointer to constant data.
1. A constant pointer to nonconstant data.
In order to calculate the ________ of an array of values, the array values must first be summed. 1. Average. 2. Minimum. 3. Maximum. 4. Distribution.
1. Average.
Which of the following is not a valid way to pass arguments to a function in C++? 1. By value with pointer arguments. 2. By value. 3. By reference with pointer arguments. 4. By reference with reference arguments.
1. By value with pointer arguments.
Referencing elements outside the array bounds with the [] operator: 1. Can result in changes to the value of an unrelated variable. 2. Is impossible because C++ checks to make sure it does not happen. 3. Is a syntax error. 4. Enlarges the size of the array.
1. Can result in changes to the value of an unrelated variable.
A string array is commonly used for: 1. Command-line arguments. 2. Storing multiple copies of the same string. 3. Displaying floating-point numbers to the screen. 4. Storing an extremely long string.
1. Command-line arguments.
Linear search is highly inefficient compared to binary search when dealing with: 1. Large, sorted arrays. 2. Large, unsorted arrays. 3. Small, unsorted arrays. 4. Small, sorted arrays.
1. Large, sorted arrays.
In a UML communication diagram, the first message passed during the processing of message 1 is called: 1. Message 1.1. 2. Message 2. 3. Message 1-1. 4. Message 0.
1. Message 1.1.
Which of the following is not true? 1. String literals are written inside of single quotes. 2. A string in C++ is an array of characters ending in the null character ('\0'). 3. A string may be assigned in a declaration to either a character array or a variable of type char *. 4. A string may include letters, digits and various special characters (i.e., +, -, * ).
1. String literals are written inside of single quotes.
To prevent modification of array values passed to a function: 1. The array parameter can be preceded by the const qualifier. 2. A copy of the array must be made inside the function. 3. The array must be passed by reference. 4. The array must be declared static in the function.
1. The array parameter can be preceded by the const qualifier.
An activation, represented by a thin vertical rectangle, on an object's lifeline indicates that: 1. The object is executing. 2. The object is waiting for another object to return control. 3. The object is instantiated in memory. 4. The object has terminated execution.
1. The object is executing.
Comparing pointers and performing pointer arithmetic on them is meaningless unless: 1. They point to elements of the same array. 2. You are trying to compare and perform pointer arithmetic on the values to which they point. 3. They point to arrays of equal size. 4. They point to arrays of the same type.
1. They point to elements of the same array.
Which of the following is not a correct way to initialize a built-in array? 1. int n[ 5 ] = { 0, 7, 0, 3, 8, 2 }; 2. int n[] = { 0, 7, 0, 3, 8, 2 }; 3. int n[ 5 ] = { 7 }; 4. int n[ 5 ] = { 9, 1, 9 };
1. int n[ 5 ] = { 0, 7, 0, 3, 8, 2 };
Which of the following is not a correct way to initialize an array? 1. int n[ 5 ] = { 0, 7, 0, 3, 8, 2 };. 2. int n[ 5 ] = { 9, 1, 9 };. 3. int n[] = { 0, 7, 0, 3, 8, 2 };. 4. int n[ 5 ] = { 7 };.
1. int n[ 5 ] = { 0, 7, 0, 3, 8, 2 };.
Assuming that t is an array and tPtr is a pointer to that array, which expression refers to the address of the fourth element? 1. tPtr[ 3 ]. 2. &t[ 3 ]. 3. *( tPtr + 3 ). 4. *( t + 3 ).
2. &t[ 3 ].
Which of the following can have a pointer as an operand? 1. /. 2. ++. 3. *=. 4. %.
2. ++.
A function that prints a string by using pointer arithmetic such as ++ptr to output each character should have a parameter that is: 1. A nonconstant pointer to nonconstant data. 2. A nonconstant pointer to constant data. 3. A constant pointer to nonconstant data. 4. A constant pointer to constant data.
2. A nonconstant pointer to constant data.
A pointer can not be assigned to: 1. Another pointer of the same type without using the cast operator. 2. A pointer of a type other than its own type and void without using the cast operator. 3. Any other pointer by using the cast operator. 4. A pointer to void without using the cast operator.
2. A pointer of a type other than its own type and void without using the cast operator.
Which of the following is not true of class template vector? 1. A vector can be assigned to another vector by using the assignment operator. 2. A vector can only store data type int. 3. The size of a vector can be changed after it is declared. 4. A vector object can be initialized with a copy of another vector by invoking the copy constructor.
2. A vector can only store data type int.
Unless otherwise specified, entire arrays are passed __________ and individual array elements are passed 1. By reference, by reference. 2. By reference, by value. 3. By value, by reference. 4. By value, by value.
2. By reference, by value.
strtok does not: 1. Replace each delimiting character with '\0'. 2. Completely tokenize the string the first time it is called. 3. Modify the input string. 4. Return a pointer to the token it creates.
2. Completely tokenize the string the first time it is called.
Using square brackets ([]) to retrieve vector elements __________ perform bounds checking; using member function at to retrieve vector elements __________ perform bounds checking. 1. Does, does not. 2. Does not, does. 3. Does, does. 4. Does not, does not.
2. Does not, does.
Which of the following is false about a function to which an array is being passed? 1. It is able to modify the values stored in the array. 2. It knows the size of the array that is being passed. 3. It is being passed the address of the first element in the array. 4. The array name is used as an argument in the function call.
2. It knows the size of the array that is being passed.
What does the following statement declare? int *countPtr, count; 1. Two int variables. 2. One pointer to an int and one int variable. 3. Two pointers to ints. 4. The declaration is invalid.
2. One pointer to an int and one int variable.
At the ith iteration of the insertion sort: 1. The ith element of the array is currently empty. 2. The first i elements of the array are sorted. 3. The ith element of the array is in its final position. 4. The last i elements of the array are sorted.
2. The first i elements of the array are sorted.
In a typical nested for loop structure used to process a two-dimensional array, following the end of the each execution of the inner for loop: 1. The outer for loop initializes its counter variable. 2. The outer for loop increments its counter variable. 3. The inner for loop increments its counter variable. 4. The inner for loop initializes its counter variable.
2. The outer for loop increments its counter variable.
Assuming that int a has a value of 3 and that integer array b has 7 elements, what is the correct way to assign the value of the third element plus 3, to the fifth element of the array: 1. b[ a + 1 ] = b[ a ] + 3;. 2. b[ a + 1 ] = b[ a - 1 ] + 3; 3. b[ a + 2 ] = b[ a ] + 3;. 4. b[ a ] + 1 = b[ a + 3];.
2. b[ a + 1 ] = b[ a - 1 ] + 3;
cin.getline( superstring, 30 ); is equivalent to which of the following? 1. cin.getline( superstring, 30, '\0' ); 2. cin.getline( superstring, 30, '\n' ); 3. cin.getline( superstring, 30, '\s' ); 4. cin.getline( superstring, 30, '\t' );
2. cin.getline( superstring, 30, '\n' );
When a compiler encounters a function parameter for a single-subscripted array of the form int a[], it converts the parameter to: 1. No conversion is necessary. 2. int * a. 3. int &a. 4. int a.
2. int * a.
When using exception handling, place any code that might throw an exception in a ________. 1. catch block 2. try statement 3. throw block 4. what statement
2. try statement
Three of the following expressions have the same value. Which of the following expressions has a value different from the others'? 1. *&Ptr. 2. &*Ptr. 3. *Ptr. 4. Ptr.
3. *Ptr.
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? 1. 2003 2. 2006 3. 2012 4. 2024
3. 2012
To follow the principle of least privilege, the selectionSort function should receive the array to be sorted as: 1. A nonconstant pointer to nonconstant data. 2. A constant pointer to constant data. 3. A constant pointer to nonconstant data. 4. A nonconstant pointer to constant data.
3. A constant pointer to nonconstant data.
A function that modifies an array by using pointer arithmetic such as ++ptr to process every value should have a parameter that is: 1. A constant pointer to nonconstant data. 2. A nonconstant pointer to nonconstant data. 3. A nonconstant pointer to constant data. 4. A constant pointer to constant data.
3. A nonconstant pointer to constant data.
A pointer cannot be assigned to: 1. Another pointer of the same type without using the cast operator. 2. A pointer to void without using the cast operator. 3. A pointer of a type other than its own type and void without using the cast operator. 4. Any other pointer by using the cast operator.
3. A pointer of a type other than its own type and void without using the cast operator.
Linear search can be used on: 1. Sorted arrays. 2. Integer arrays. 3. Any of the above. 4. Unsorted arrays.
3. Any of the above.
Pointers may be assigned to which of the following? 1. Any integer values. 2. An address. 3. Both (b) and (c). 4. NULL.
3. Both (b) and (c).
Constant variables: 1. Can be assigned values in executable statements. 2. Do not have to be initialized when they are declared. 3. Can be used to specify array sizes, thereby making programs more scalable. 4. Can be used to specify array sizes, but this makes programs harder to understand.
3. Can be used to specify array sizes, thereby making programs more scalable.
Strings represented as character arrays cannot: 1. Be initialized with initializer lists. 2. Be used with cout and cin. 3. Grow or shrink dynamically. 4. Be initialized using string literals.
3. Grow or shrink dynamically.
( *max )( num1, num2, num3 );: 1. Is the prototype for function max. 2. Is the header for function max. 3. Is a call to the function pointed to by max. 4. Is a declaration of a pointer to a function called max.
3. Is a call to the function pointed to by max.
A string array: 1. Can only provide access to strings of a certain length. 2. Is always less memory efficient than an equivalent double-subscripted array. 3. Is actually an array of pointers. 4. Stores an actual string in each of its elements.
3. Is actually an array of pointers.
An array is not: 1. A consecutive group of memory locations. 2. Subscripted by integers. 3. Made up of different data types. 4. None of these.
3. Made up of different data types.
sizeof: 1. Is a binary operator. 2. Returns the total number of elements in an array. 3. Returns the total number of bytes in a variable. 4. Usually returns a double.
3. Returns the total number of bytes in a variable.
An algorithm that could execute for an unknown amount of time because it depends on random numbers may: 1. Issue a compiler error. 2. Have a redundancy. 3. Suffer from indefinite postponement. 4. Get caught in an infinite loop.
3. Suffer from indefinite postponement.
After the ith iteration of the selection sort: 1. None of the above. 2. The smallest i items of the array will be sorted into decreasing order in the first i elements of the array. 3. The smallest i items of the array will be sorted into increasing order in the first i elements of the array. 4. The largest i items of the array will be sorted into decreasing order in the last i elements of the array.
3. The smallest i items of the array will be sorted into increasing order in the first i elements of the array.
Which of the following is not true of pointers to functions? 1. They contain the starting address of the function code. 2. They can be stored in arrays. 3. They can not be assigned to other function pointers. 4. They are dereferenced in order to call the function.
3. They can not be assigned to other function pointers.
Assume that the array named items contains the integer values 0, 2, 4, 6 and 8. Which of the following set of statements uses the range-based for loop to display each value in items? 1. for ( int i = 0; i < items.size(); ++i ) cout << items[ i ] << endl; 2. for ( int item : items ) cout << items[ item ] << endl; 3. for ( int item : items ) cout << item << endl; 4. for ( int item : i < items.size() ) cout << item << endl;
3. for ( int item : items ) cout << item << endl;
The & operator can be applied to: 1. constants. 2. rvalues. 3. lvalues. 4. string literals.
3. lvalues.
Which of the following best describes the array name n in the declaration int n[10];? 1. n is a nonconstant pointer to nonconstant data. 2. n is a nonconstant pointer to constant data. 3. n is a constant pointer to nonconstant data. 4. n is a constant pointer to constant data.
3. n is a constant pointer to nonconstant data.
Which of the following gives the number of elements in the array int r[ 10 ]? 1. sizeof r 2. sizeof ( *r ) 3. sizeof r / sizeof ( int ) 4. sizeof ( *r ) / sizeof ( int )
3. sizeof r / sizeof ( int )
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: 1. A nonconstant pointer to nonconstant data. 2. A nonconstant pointer to constant data. 3. A constant pointer to nonconstant data. 4. A constant pointer to constant data.
4. A constant pointer to constant data.
A message between two objects in a UML sequence diagram is represented by: 1. A dashed line with a filled arrowhead. 2. A solid line with a stick arrowhead. 3. A dashed line with a stick arrowhead. 4. A solid line with a filled arrowhead.
4. A solid line with a filled arrowhead.
Which of the following is not true? 1. The first element of an array is the zeroth. 2. The position number contained within square brackets is called a subscript. 3. The last element of an array has position number one less than the array size. 4. A subscript cannot be an expression.
4. A subscript cannot be an expression.
Which of the following tasks cannot be performed using a range-based for loop? 1. Calculating the product of all the values in an array. 2. Displaying all even element values in an array. 3. Incrementing the value stored in each element of the array. 4. Accessing the element's subscript.
4. Accessing the element's subscript.
Which of the following does not declare a 2-by-2 array and set all four of its elements to 0? 1. int b[ 2 ][ 2 ]; for ( int i = 0; i < 2; i++ ) for ( int j = 0; j < 2; j++ ) b[ i ][ j ] = 0;. 2. int b [ 2 ][ 2 ]; b[ 0 ][ 0 ] = b[ 0 ][ 1 ] = b[ 1 ][ 0] = b[ 1 ][ 1 ] = 0;. 3. int b[ 2 ][ 2 ] = { 0 };. 4. All of the above initialize all of their elements to 0.
4. All of the above initialize all of their elements to 0.
Pointers may be assigned which of the following values? 1. Any integer values. 2. An address. 3. nullptr. 4. Both An address and nullptr.
4. Both An address and nullptr.
All of the following could cause a fatal execution-time error except: 1. Dereferencing a null pointer. 2. Dereferencing a pointer that has not been assigned to point to a specific address. 3. Dereferencing a pointer that has not been initialized properly. 4. Dereferencing a variable that is not a pointer.
4. Dereferencing a variable that is not a pointer.
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? 1. Array subscript notation. 2. Pointer/offset notation where the pointer is actually the name of the array. 3. Pointer subscript notation. 4. Pointer/offset notation.
4. Pointer/offset notation.
Pointers cannot be used to: 1. Pass an argument by reference. 2. Manipulate dynamic data structures. 3. Contain memory addresses. 4. Reference values directly.
4. Reference values directly.
sizeof: 1. Is a binary operator. 2. Returns the total number of elements in an array. 3. Usually returns a double. 4. Returns the total number of bytes in a variable.
4. Returns the total number of bytes in a variable.
Assuming that string1 = "hello" and string2 = "hello world", which of the following returns 0? 1. strncmp( string1, string2, 6 );. 2. strcmp( string1, string2, 6 );. 3. strcmp( string1, string2 );. 4. Strncmp( string1, string2, 5 );.
4. Strncmp( string1, string2, 5 );.
Which statement about insertion sort is true? 1. A maximum of n comparisons are needed to sort the array, where n is the number of elements. 2. No temporary variables are needed. 3. Performance is maximized. 4. The algorithm is very simple compared to other sorting procedures.
4. The algorithm is very simple compared to other sorting procedures.
Which of the following character array declarations does not produce a string? 1. char string1[] = " ";. 2. char string1[] = "test";. 3. char string1[] = { 't', 'e', 's', 't', '\0' };. 4. char string1[] = { 't', 'e', 's', 't' };.
4. char string1[] = { 't', 'e', 's', 't' };.
Which statement would be used to declare a 10-element integer array c? 1. int array c[ 10 ];. 2. array c = int[ 10 ];. 3. c = int[ 10 ];. 4. int c[ 10 ];.
4. int c[ 10 ];.
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"? 1. strncpy( string1, string2, 6 );. 2. strcpy( string1, string2, 6 );. 3. Strncpy( string1, string2, 5 );. 4. strcpy( string1, string2 );.
4. strcpy( string1, string2 );.
Given the following declaration, what is the value of b[ 1 ][ 0 ]? int b[ 2 ][ 2 ] = { { 1 }, { 3 , 4 } }; A. 3. B. This is not a valid declaration. C. 1. D. 0.
A. 3.
A double subscripted array element declared as a[ 3 ][ 5 ] has how many elements? A. 10. B. 13. C. 15. D. 8.
C. 15.