Deck 7: Pointers and Pointer-Based Strings

Full screen (f)
exit full mode
Question
Which of the following best describes the array name n in the declaration int n[10];?

A) n is a nonconstant pointer to nonconstant data.
B) n is a nonconstant pointer to constant data.
C) n is a constant pointer to nonconstant data.
D) n is a constant pointer to constant data.
Use Space or
up arrow
down arrow
to flip the card.
Question
Sizeof:

A) Is a binary operator.
B) Returns the total number of elements in an array.
C) Usually returns a double.
D) Returns the total number of bytes in a variable.
Question
A pointer can not be assigned to:

A) Another pointer of the same type without using the cast operator.
B) A pointer to void without using the cast operator.
C) A pointer of a type other than its own type and void without using the cast operator.
D) Any other pointer by using the cast operator.
Question
To follow the principle of least privilege, the selectionSort function should receive the array to be sorted as:

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.
Question
Which of the following is not a valid way to pass arguments to a function in C++?

A) By reference with reference arguments.
B) By value.
C) By reference with pointer arguments.
D) By value with pointer arguments.
Question
All of the following can cause a fatal execution-time error except:

A) Dereferencing a pointer that has not been assigned to point to a specific address.
B) Dereferencing a pointer that has not been initialized properly.
C) Dereferencing a null pointer.
D) Dereferencing a variable that is not a pointer.
Question
A function that modifies an array by using pointer arithmetic such as ++ptr to process every value should have a parameter that is:

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.
Question
What does the following statement declare?
Int *countPtr, count;

A) Two int variables.
B) One pointer to an int and one int variable.
C) Two pointers to ints.
D) The declaration is invalid.
Question
Three of the following 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
Question
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.
Question
After the ith iteration of the selection sort:

A) The smallest i items of the array will be sorted into decreasing order in the first i elements of the array.
B) The largest i items of the array will be sorted into decreasing order in the last i elements of the array.
C) The smallest i items of the array will be sorted into increasing order in the first i elements of the array.
D) None of the above.
Question
The & operator can be applied to:

A) constants.
B) string literals.
C) lvalues.
D) rvalues.
Question
Pointers may be assigned which of the following values?

A) Any integer values.
B) An address.
C) NULL.
D) Both b) and c).
Question
Which of the following gives the number of elements in the array int r[ 10 ]?

A) sizeof r
B) sizeof *r )
C) sizeof r / sizeof int )
D) sizeof *r ) / sizeof int )
Question
A function that prints a string by using pointer arithmetic such as ++ptr to output each character should have a parameter that is:

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.
Question
When a compiler encounters a function parameter for a single-subscripted array of the form int a[], it converts the parameter to:

A) int a
B) int &a
C) int *a
D) No conversion is necessary.
Question
Pointers cannot be used to:

A) Contain memory addresses.
B) Reference values directly.
C) Pass an argument by reference.
D) Manipulate dynamic data structures.
Question
Comparing pointers and performing pointer arithmetic on them is meaningless unless:

A) They point to elements of the same array.
B) You are trying to compare and perform pointer arithmetic on the values to which they point.
C) They point to arrays of equal size.
D) They point to arrays of the same type.
Question
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?

A) 2003
B) 2006
C) 2012
D) 2024
Question
Which of the following can have a pointer as an operand?

A) ++
B) *=
C) %
D) /
Question
getline superstring, 30 );
Is equivalent to which of the following?

A) cin.getline superstring, 30, '\0' );
B) cin.getline superstring, 30, '\n' );
C) cin.getline superstring, 30, '\s' );
D) cin.getline superstring, 30, '\t' );
Question
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?

A) Array subscript notation.
B) Pointer/offset notation where the pointer is actually the name of the array.
C) Pointer subscript notation.
D) Pointer/offset notation.
Question
A string array is commonly used for:

A) Command-line arguments.
B) Storing an extremely long string.
C) Storing multiple copies of the same string.
D) Displaying floating-point numbers to the screen.
Question
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?

A) * tPtr + 3 )
B) tPtr[ 3 ]
C) &t[ 3 ]
D) * t + 3 )
Question
Which of the following is false for pointer-based strings?

A) A string may include letters, digits and various special characters i.e., +, -, * ).
B) A string in C++ is an array of characters ending in the null character '\0').
C) String literals are written inside of single quotes.
D) A string may be assigned in a declaration to either a character array or a variable of type char *.
Question
Which of the following is not true of pointers to functions?

A) They contain the starting address of the function code.
B) They are dereferenced in order to call the function.
C) They can be stored in arrays.
D) They can not be assigned to other function pointers.
Question
A string array:

A) Stores an actual string in each of its elements.
B) Can only provide access to strings of a certain length.
C) Is actually an array of pointers.
D) Is always less memory efficient than an equivalent double-subscripted array.
Question
*max ) num1, num2, num3 );:

A) Is the header for function max.
B) Is a call to the function pointed to by max.
C) Is the prototype for function max.
D) Is a declaration of a pointer to a function called max.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/28
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 7: Pointers and Pointer-Based Strings
1
Which of the following best describes the array name n in the declaration int n[10];?

A) n is a nonconstant pointer to nonconstant data.
B) n is a nonconstant pointer to constant data.
C) n is a constant pointer to nonconstant data.
D) n is a constant pointer to constant data.
C
2
Sizeof:

A) Is a binary operator.
B) Returns the total number of elements in an array.
C) Usually returns a double.
D) Returns the total number of bytes in a variable.
D
3
A pointer can not be assigned to:

A) Another pointer of the same type without using the cast operator.
B) A pointer to void without using the cast operator.
C) A pointer of a type other than its own type and void without using the cast operator.
D) Any other pointer by using the cast operator.
C
4
To follow the principle of least privilege, the selectionSort function should receive the array to be sorted as:

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.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
5
Which of the following is not a valid way to pass arguments to a function in C++?

A) By reference with reference arguments.
B) By value.
C) By reference with pointer arguments.
D) By value with pointer arguments.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
6
All of the following can cause a fatal execution-time error except:

A) Dereferencing a pointer that has not been assigned to point to a specific address.
B) Dereferencing a pointer that has not been initialized properly.
C) Dereferencing a null pointer.
D) Dereferencing a variable that is not a pointer.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
7
A function that modifies an array by using pointer arithmetic such as ++ptr to process every value should have a parameter that is:

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.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
8
What does the following statement declare?
Int *countPtr, count;

A) Two int variables.
B) One pointer to an int and one int variable.
C) Two pointers to ints.
D) The declaration is invalid.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
9
Three of the following 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
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
10
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.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
11
After the ith iteration of the selection sort:

A) The smallest i items of the array will be sorted into decreasing order in the first i elements of the array.
B) The largest i items of the array will be sorted into decreasing order in the last i elements of the array.
C) The smallest i items of the array will be sorted into increasing order in the first i elements of the array.
D) None of the above.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
12
The & operator can be applied to:

A) constants.
B) string literals.
C) lvalues.
D) rvalues.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
13
Pointers may be assigned which of the following values?

A) Any integer values.
B) An address.
C) NULL.
D) Both b) and c).
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
14
Which of the following gives the number of elements in the array int r[ 10 ]?

A) sizeof r
B) sizeof *r )
C) sizeof r / sizeof int )
D) sizeof *r ) / sizeof int )
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
15
A function that prints a string by using pointer arithmetic such as ++ptr to output each character should have a parameter that is:

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.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
16
When a compiler encounters a function parameter for a single-subscripted array of the form int a[], it converts the parameter to:

A) int a
B) int &a
C) int *a
D) No conversion is necessary.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
17
Pointers cannot be used to:

A) Contain memory addresses.
B) Reference values directly.
C) Pass an argument by reference.
D) Manipulate dynamic data structures.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
18
Comparing pointers and performing pointer arithmetic on them is meaningless unless:

A) They point to elements of the same array.
B) You are trying to compare and perform pointer arithmetic on the values to which they point.
C) They point to arrays of equal size.
D) They point to arrays of the same type.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
19
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?

A) 2003
B) 2006
C) 2012
D) 2024
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
20
Which of the following can have a pointer as an operand?

A) ++
B) *=
C) %
D) /
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
21
getline superstring, 30 );
Is equivalent to which of the following?

A) cin.getline superstring, 30, '\0' );
B) cin.getline superstring, 30, '\n' );
C) cin.getline superstring, 30, '\s' );
D) cin.getline superstring, 30, '\t' );
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
22
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?

A) Array subscript notation.
B) Pointer/offset notation where the pointer is actually the name of the array.
C) Pointer subscript notation.
D) Pointer/offset notation.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
23
A string array is commonly used for:

A) Command-line arguments.
B) Storing an extremely long string.
C) Storing multiple copies of the same string.
D) Displaying floating-point numbers to the screen.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
24
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?

A) * tPtr + 3 )
B) tPtr[ 3 ]
C) &t[ 3 ]
D) * t + 3 )
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
25
Which of the following is false for pointer-based strings?

A) A string may include letters, digits and various special characters i.e., +, -, * ).
B) A string in C++ is an array of characters ending in the null character '\0').
C) String literals are written inside of single quotes.
D) A string may be assigned in a declaration to either a character array or a variable of type char *.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
26
Which of the following is not true of pointers to functions?

A) They contain the starting address of the function code.
B) They are dereferenced in order to call the function.
C) They can be stored in arrays.
D) They can not be assigned to other function pointers.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
27
A string array:

A) Stores an actual string in each of its elements.
B) Can only provide access to strings of a certain length.
C) Is actually an array of pointers.
D) Is always less memory efficient than an equivalent double-subscripted array.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
28
*max ) num1, num2, num3 );:

A) Is the header for function max.
B) Is a call to the function pointed to by max.
C) Is the prototype for function max.
D) Is a declaration of a pointer to a function called max.
Unlock Deck
Unlock for access to all 28 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 28 flashcards in this deck.