Chapter 9 Flashcards Preview

Computer Science > Chapter 9 > Flashcards

Flashcards in Chapter 9 Deck (35)
Loading flashcards...
1

What does the indirection operator do?

It dereferences a pointer, allowing code to work with the value that the pointer points to

2

What are the 3 different uses for the * operator?

1. multiplication operator
2. definition of a pointer variable
3. the indirection operator

3

What mathematical operations are allowed on pointers?

Addition and subtraction

4

Assuming that ptr is a pointer to an int, what happens when you add 4 to ptr?

It adds 4 times the size of an int to the address stored in ptr

5

What is the purpose of the new operator?

To dynamically allocate memory

6

What is the purpose of the delete operator?

to free memory that has been dynamically allocated with the new operator

7

Under what circumstances can you successfully return a pointer from a function?

you should only return a pointer from a function if it is:
- a pointer to an object that was passed into the function as an argument
- a pointer to a dynamically allocated object

8

Each byte in memory is assigned a unique ______.

Address

9

The ______ operator can be used to determine a variable's address

& (ampersand)

10

_______ variables are designed to hold addresses.

Pointer

11

The _______ operator can be used to work with the variable a pointer points to.

Indirection ( * )

12

Array names can be used as ______, and vice versa.

Pointers

13

Creating variables while a program is running is called.

Dynamic memory allocation

14

The _____ operator is used to dynamically allocate memory.

new

15

Under older compilers, if the new operator cannot allocate the amount of memory requested, it returns _____.

null (/zero)

16

A pointer that contains the address 0 is called a(n) ____ pointer.

null

17

When a program is finished with a chunk of dynamically allocated memory, it should free it with the _____ operator.

delete

18

You should only use pointers with delete that were previously used with _____.

new

19

[T/F]
Each byte of memory is assigned a unique address

true

20

[T/F]
The * operator is used to get the address of a variable

false

21

[T/F]
Pointer variables are designed to hold addresses

true

22

[T/F]
The & symbol is called the indirection operator

false

23

[T/F]
The & operator dereferences a pointer

false

24

[T/F]
When the indirection operator is used with a pointer variable, you are actually working with the value the pointer is pointing to

true

25

[T/F]
Array names cannot be dereferenced with the indirection operator

false

26

[T/F]
When you add a value to a pointer, you are actually adding that number times the size of the data type referenced by the pointer.

true

27

[T/F]
The address operator is not needed to assign an array's address to a pointer

true

28

[T/F]
You can change the address that an array name points to

false

29

[T/F]
Any mathematical operation, including multiplication and division, may be performed on a pointer

false

30

[T/F]
Pointers may be compared using the relational operators

true