Deck 10: Pointers

Full screen (f)
exit full mode
Question
Which of the following statements is not valid C++ code?

A)float num1 = &ptr2;
B)int ptr = &num1;
C)int ptr = int *num1;
D)All of the above are valid.
E)All of the above are invalid.
Use Space or
up arrow
down arrow
to flip the card.
Question
To dereference a structure pointer and simultaneously access a member of the structure, the appropriate operator to use is

A)an asterisk, *.
B)the dereference operator, <-.
C)the structure pointer operator, ->.
D)the ampersand, &.
E)None of the above
Question
A function may return a pointer, but the programmer must ensure that the pointer

A)is pointing to an object that is still valid after the return of the function.
B)was received as a parameter by the function.
C)has been assigned an address.
D)has not previously been returned by another function.
E)None of the above
Question
Which arithmetic operations can be performed on pointers?

A)Multiplication, division, addition, and subtraction
B)Addition , subtraction , preincrement, and postincrement
C)Only multiplication and addition
D)All arithmetic operations that are legal in C++
E)None of the above
Question
The and operators can respectively be used to increment and decrement a pointer variable.
A)All of the above

A)modulus, division
B)None of the above
B)dereferencing, indirection C)++, --
Question
A statement that displays the address of the variable num1 is

A)cout << &(*num1);.
B)cout << &num1;.
C)cout << num1;.
D)cout << *num1;.
E)None of the above
Question
The statement int *ptr; means

A)the variable called *ptr will store an asterisk and an integer value.
B)ptr is a pointer variable that will store the address of an integer variable.
C)the variable called ptr will store an integer value.
D)All of the above
E)None of the above
Question
Any time you use the new operator, it is good practice to

A)clear the data from the old operator
B)use a preprocessor directive.
C)use delete afterwards to free the memory allocated by new.
D)All of the above
E)None of the above
Question
If arr is an array identifier and k is an integer, the expression arr[k] is equivalent to

A)&arr[k].
B)arr + k.
C)*(arr + k).
D)*arr + k.
E)None of the above
Question
When the less than ( < )operator is used between two pointer variables, the expression is testing whether

A)the address of the first variable comes before the address of the second variable in the computer's memory.
B)the value pointed to by the first is less than the value pointed to by the second.
C)the first variable was declared before the second variable.
D)the value pointed to by the first is greater than the value pointed to by the second.
E)None of the above
Question
The statement double *num;

A)defines a pointer variable called num.
B)defines a variable of type double called num.
C)initializes a variable called *num.
D)defines and initializes a pointer variable called num.
E)None of the above
Question
The code segment int *ptr; has the same meaning as

A)int* ptr;.
B)int ptr*;.
C)*int ptr;.
D)int ptr;.
E)None of the above
Question
If s is a structure variable and p, a pointer, is a member of the structure, the statement cout << *s.p; will

A)output the value stored in s.
B)output the dereferenced value pointed to by p.
C)output the address stored in p.
D)result in a compiler error.
E)None of the above
Question
The statement cout << *ptr; will output

A)the address of the variable stored in ptr.
B)the string "*ptr".
C)the value stored in the variable whose address is contained in ptr.
D)the address of the variable whose address is stored in ptr.
E)None of the above
Question
You may use the type pointer to a structure as the type of a

A)function parameter.
B)function return type.
C)structure member.
D)All of the above
E)None of the above
Question
The statement cin >> *p;

A)stores the keyboard input into the variable pointed to by p.
B)is illegal in C++.
C)stores the keyboard input into the pointer called p.
D)stores the keyboard input into the variable p.
E)None of the above
Question
When you work with a dereferenced pointer, you are actually working with

A)a copy of the value pointed to by the pointer variable.
B)a variable whose memory has been deallocated.
C)the variable whose address is stored in the pointer variable.
D)All of the above
E)None of the above
Question
The , also known as the address operator, returns the memory address of a variable.

A)exclamation point ( ! )
B)asterisk ( * )
C)ampersand ( & )
D)percent sign (%)
E)None of the above
Question
Assuming that arris an array identifier, the statement sum += *arr;

A)will always result in a compiler error.
B)is illegal in C++.
C)adds the address of the pointer arr to sum.
D)adds the value stored in arr[0] to sum.
E)None of the above
Question
Every byte in the computer's memory is assigned a unique

A)name.
B)address.
C)dynamically allocated value.
D)value.
E)None of the above
Question
The expression *s->p; is only meaningful if s is a pointer to a structure and p is a pointer that is a member of that structure.
Question
It is possible for a structure to contain as a member a pointer to its own structure type.
Question
A pointer with the value 0 (zero)is called the NULL pointer.
Question
When the is placed in front of a variable name, it returns the address of that variable.

A)asterisk ( * )
B)ampersand ( & )
C)semicolon ( ; )
D)conditional operator
E)None of the above
Question
Which of the following statements correctly deletes a dynamically- allocated array pointed to by p?

A)delete [ ] p;
B)delete array p;
C)delete p;
D)p delete[ ];
E)None of the above
Question
If dynamically allocated memory is not freed,

A)a run- time error informs your user that the program did not free memory space.
B)the source code will not link correctly.
C)the system may run out of memory.
D)it results in a compiler error.
E)None of the above
Question
A pointer may be initialized with

A)the value of a floating- point variable.
B)the address of an existing object of the appropriate type.
C)the value of a floating- point constant.
D)All of the above
E)None of the above
Question
If a variable occupies more than one byte of memory, its address is

A)general delivery.
B)the address of the last byte of storage allocated to it.
C)the average of the addresses used to store the variable.
D)the address of the first byte of storage allocated to it.
E)None of the above
Question
The delete operator should only be used on pointers that

A)have been correctly initialized.
B)have not yet been used.
C)are appropriately dereferenced.
D)point to storage allocated by the new operator.
E)None of the above
Question
If Circle is a structure type, the statement Circle *pcirc;

A)defines a structure variable called *pcirc.
B)initializes a Circle pointer.
C)defines a structure pointer called pcirc.
D)is illegal in C++.
E)None of the above
Question
A pointer variable is designed to store

A)a memory address.
B)an integer.
C)any legal C++ value.
D)only floating- point values.
E)None of the above
Question
With pointer variables you can access, but you cannot modify, data in other variables.
Question
A pointer variable may be initialized with

A)the address of an existing variable of the appropriate type.
B)any non- zero integer value.
C)A and B are both true.
D)None of the above
Question
With pointer variables, you can manipulate data stored in other variables.

A)seldom
B)never
C)indirectly
D)All of the above
E)None of the above
Question
can be used as pointers.

A)C++ string objects
B)Punctuation marks
C)Array names
D)All of the above
E)None of the above
Question
The term pointer can be used interchangeably with

A)address.
B)decimal pointer.
C)variable.
D)counter pointer.
E)None of the above
Question
The statement int *ptr = new int; acquires memory to hold an integer and then

A)creates a new pointer called int.
B)sets ptr to point to the allocated memory.
C)initializes the allocated memory to 0.
D)assigns an integer value to the variable called ptr.
E)None of the above
Question
Dynamic memory allocation occurs

A)when a pointer is assigned an incorrect address.
B)when a variable is created at run- time.
C)when a pointer fails to dereference the right variable.
D)when a variable is created by the compiler.
E)None of the above
Question
A reason for passing a pointer to a function is

A)to allow the called function to modify a variable accessible to the calling function.
B)to avoid the overhead of copying large data structures.
C)to allow easy access to data in the function that is being called.
D)A and B are both true.
E)None of the above
Question
The statement cout << &num1; will output

A)the memory address of the variable called num1.
B)the value stored in the variable called num1.
C)the number 1.
D)the string "&num1".
E)None of the above
Question
Any arithmetic operation may be performed on pointers.
Question
A pointer can be passed as an argument to a function.
Question
The expression s->m has the same meaning as (*s).m.
Question
The expression s->m is meaningful only when s is a pointer to a structure and m is a member of the structure.
Question
The statement Rectangle * boxPtr; defines a variable boxPtr to be a pointer pointing to a type Rectangle.
Question
The ampersand (&)is used to dereference a pointer variable in C++.
Question
C++ does not perform array bounds checking.
Question
It is legal to subtract a pointer variable from another pointer variable.
Question
An array name is a pointer constant because the address it represents cannot be changed during run- time.
Question
Memory cannot be allocated after a program is already running.
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/50
auto play flashcards
Play
simple tutorial
Full screen (f)
exit full mode
Deck 10: Pointers
1
Which of the following statements is not valid C++ code?

A)float num1 = &ptr2;
B)int ptr = &num1;
C)int ptr = int *num1;
D)All of the above are valid.
E)All of the above are invalid.
E
2
To dereference a structure pointer and simultaneously access a member of the structure, the appropriate operator to use is

A)an asterisk, *.
B)the dereference operator, <-.
C)the structure pointer operator, ->.
D)the ampersand, &.
E)None of the above
C
3
A function may return a pointer, but the programmer must ensure that the pointer

A)is pointing to an object that is still valid after the return of the function.
B)was received as a parameter by the function.
C)has been assigned an address.
D)has not previously been returned by another function.
E)None of the above
A
4
Which arithmetic operations can be performed on pointers?

A)Multiplication, division, addition, and subtraction
B)Addition , subtraction , preincrement, and postincrement
C)Only multiplication and addition
D)All arithmetic operations that are legal in C++
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
5
The and operators can respectively be used to increment and decrement a pointer variable.
A)All of the above

A)modulus, division
B)None of the above
B)dereferencing, indirection C)++, --
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
6
A statement that displays the address of the variable num1 is

A)cout << &(*num1);.
B)cout << &num1;.
C)cout << num1;.
D)cout << *num1;.
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
7
The statement int *ptr; means

A)the variable called *ptr will store an asterisk and an integer value.
B)ptr is a pointer variable that will store the address of an integer variable.
C)the variable called ptr will store an integer value.
D)All of the above
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
8
Any time you use the new operator, it is good practice to

A)clear the data from the old operator
B)use a preprocessor directive.
C)use delete afterwards to free the memory allocated by new.
D)All of the above
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
9
If arr is an array identifier and k is an integer, the expression arr[k] is equivalent to

A)&arr[k].
B)arr + k.
C)*(arr + k).
D)*arr + k.
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
10
When the less than ( < )operator is used between two pointer variables, the expression is testing whether

A)the address of the first variable comes before the address of the second variable in the computer's memory.
B)the value pointed to by the first is less than the value pointed to by the second.
C)the first variable was declared before the second variable.
D)the value pointed to by the first is greater than the value pointed to by the second.
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
11
The statement double *num;

A)defines a pointer variable called num.
B)defines a variable of type double called num.
C)initializes a variable called *num.
D)defines and initializes a pointer variable called num.
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
12
The code segment int *ptr; has the same meaning as

A)int* ptr;.
B)int ptr*;.
C)*int ptr;.
D)int ptr;.
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
13
If s is a structure variable and p, a pointer, is a member of the structure, the statement cout << *s.p; will

A)output the value stored in s.
B)output the dereferenced value pointed to by p.
C)output the address stored in p.
D)result in a compiler error.
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
14
The statement cout << *ptr; will output

A)the address of the variable stored in ptr.
B)the string "*ptr".
C)the value stored in the variable whose address is contained in ptr.
D)the address of the variable whose address is stored in ptr.
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
15
You may use the type pointer to a structure as the type of a

A)function parameter.
B)function return type.
C)structure member.
D)All of the above
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
16
The statement cin >> *p;

A)stores the keyboard input into the variable pointed to by p.
B)is illegal in C++.
C)stores the keyboard input into the pointer called p.
D)stores the keyboard input into the variable p.
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
17
When you work with a dereferenced pointer, you are actually working with

A)a copy of the value pointed to by the pointer variable.
B)a variable whose memory has been deallocated.
C)the variable whose address is stored in the pointer variable.
D)All of the above
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
18
The , also known as the address operator, returns the memory address of a variable.

A)exclamation point ( ! )
B)asterisk ( * )
C)ampersand ( & )
D)percent sign (%)
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
19
Assuming that arris an array identifier, the statement sum += *arr;

A)will always result in a compiler error.
B)is illegal in C++.
C)adds the address of the pointer arr to sum.
D)adds the value stored in arr[0] to sum.
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
20
Every byte in the computer's memory is assigned a unique

A)name.
B)address.
C)dynamically allocated value.
D)value.
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
21
The expression *s->p; is only meaningful if s is a pointer to a structure and p is a pointer that is a member of that structure.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
22
It is possible for a structure to contain as a member a pointer to its own structure type.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
23
A pointer with the value 0 (zero)is called the NULL pointer.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
24
When the is placed in front of a variable name, it returns the address of that variable.

A)asterisk ( * )
B)ampersand ( & )
C)semicolon ( ; )
D)conditional operator
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
25
Which of the following statements correctly deletes a dynamically- allocated array pointed to by p?

A)delete [ ] p;
B)delete array p;
C)delete p;
D)p delete[ ];
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
26
If dynamically allocated memory is not freed,

A)a run- time error informs your user that the program did not free memory space.
B)the source code will not link correctly.
C)the system may run out of memory.
D)it results in a compiler error.
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
27
A pointer may be initialized with

A)the value of a floating- point variable.
B)the address of an existing object of the appropriate type.
C)the value of a floating- point constant.
D)All of the above
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
28
If a variable occupies more than one byte of memory, its address is

A)general delivery.
B)the address of the last byte of storage allocated to it.
C)the average of the addresses used to store the variable.
D)the address of the first byte of storage allocated to it.
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
29
The delete operator should only be used on pointers that

A)have been correctly initialized.
B)have not yet been used.
C)are appropriately dereferenced.
D)point to storage allocated by the new operator.
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
30
If Circle is a structure type, the statement Circle *pcirc;

A)defines a structure variable called *pcirc.
B)initializes a Circle pointer.
C)defines a structure pointer called pcirc.
D)is illegal in C++.
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
31
A pointer variable is designed to store

A)a memory address.
B)an integer.
C)any legal C++ value.
D)only floating- point values.
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
32
With pointer variables you can access, but you cannot modify, data in other variables.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
33
A pointer variable may be initialized with

A)the address of an existing variable of the appropriate type.
B)any non- zero integer value.
C)A and B are both true.
D)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
34
With pointer variables, you can manipulate data stored in other variables.

A)seldom
B)never
C)indirectly
D)All of the above
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
35
can be used as pointers.

A)C++ string objects
B)Punctuation marks
C)Array names
D)All of the above
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
36
The term pointer can be used interchangeably with

A)address.
B)decimal pointer.
C)variable.
D)counter pointer.
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
37
The statement int *ptr = new int; acquires memory to hold an integer and then

A)creates a new pointer called int.
B)sets ptr to point to the allocated memory.
C)initializes the allocated memory to 0.
D)assigns an integer value to the variable called ptr.
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
38
Dynamic memory allocation occurs

A)when a pointer is assigned an incorrect address.
B)when a variable is created at run- time.
C)when a pointer fails to dereference the right variable.
D)when a variable is created by the compiler.
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
39
A reason for passing a pointer to a function is

A)to allow the called function to modify a variable accessible to the calling function.
B)to avoid the overhead of copying large data structures.
C)to allow easy access to data in the function that is being called.
D)A and B are both true.
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
40
The statement cout << &num1; will output

A)the memory address of the variable called num1.
B)the value stored in the variable called num1.
C)the number 1.
D)the string "&num1".
E)None of the above
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
41
Any arithmetic operation may be performed on pointers.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
42
A pointer can be passed as an argument to a function.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
43
The expression s->m has the same meaning as (*s).m.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
44
The expression s->m is meaningful only when s is a pointer to a structure and m is a member of the structure.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
45
The statement Rectangle * boxPtr; defines a variable boxPtr to be a pointer pointing to a type Rectangle.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
46
The ampersand (&)is used to dereference a pointer variable in C++.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
47
C++ does not perform array bounds checking.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
48
It is legal to subtract a pointer variable from another pointer variable.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
49
An array name is a pointer constant because the address it represents cannot be changed during run- time.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
50
Memory cannot be allocated after a program is already running.
Unlock Deck
Unlock for access to all 50 flashcards in this deck.
Unlock Deck
k this deck
locked card icon
Unlock Deck
Unlock for access to all 50 flashcards in this deck.