Deck 7: Pointers and Pointer-Based Strings

ملء الشاشة (f)
exit full mode
سؤال
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.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
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.
سؤال
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.
سؤال
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.
سؤال
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.
سؤال
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.
سؤال
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.
سؤال
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.
سؤال
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
سؤال
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.
سؤال
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.
سؤال
The & operator can be applied to:

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

A) Any integer values.
B) An address.
C) NULL.
D) Both b) and c).
سؤال
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 )
سؤال
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.
سؤال
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.
سؤال
Pointers cannot be used to:

A) Contain memory addresses.
B) Reference values directly.
C) Pass an argument by reference.
D) Manipulate dynamic data structures.
سؤال
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.
سؤال
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
سؤال
Which of the following can have a pointer as an operand?

A) ++
B) *=
C) %
D) /
سؤال
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' );
سؤال
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.
سؤال
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.
سؤال
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 )
سؤال
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 *.
سؤال
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.
سؤال
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.
سؤال
*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 Deck
1/28
auto play flashcards
العب
simple tutorial
ملء الشاشة (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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
k this deck
12
The & operator can be applied to:

A) constants.
B) string literals.
C) lvalues.
D) rvalues.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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).
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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 )
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
k this deck
20
Which of the following can have a pointer as an operand?

A) ++
B) *=
C) %
D) /
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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' );
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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 )
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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 *.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
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.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 28 في هذه المجموعة.