Chapter 9 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What does the indirection operator do?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What are the 3 different uses for the * operator?

A
  1. multiplication operator
  2. definition of a pointer variable
  3. the indirection operator
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What mathematical operations are allowed on pointers?

A

Addition and subtraction

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

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

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the purpose of the new operator?

A

To dynamically allocate memory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the purpose of the delete operator?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

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

A

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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Each byte in memory is assigned a unique ______.

A

Address

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

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

A

& (ampersand)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

_______ variables are designed to hold addresses.

A

Pointer

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

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

A

Indirection ( * )

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

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

A

Pointers

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Creating variables while a program is running is called.

A

Dynamic memory allocation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

The _____ operator is used to dynamically allocate memory.

A

new

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

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

A

null (/zero)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

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

A

null

17
Q

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

A

delete

18
Q

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

A

new

19
Q

[T/F]

Each byte of memory is assigned a unique address

A

true

20
Q

[T/F]

The * operator is used to get the address of a variable

A

false

21
Q

[T/F]

Pointer variables are designed to hold addresses

A

true

22
Q

[T/F]

The & symbol is called the indirection operator

A

false

23
Q

[T/F]

The & operator dereferences a pointer

A

false

24
Q

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

A

true

25
Q

[T/F]

Array names cannot be dereferenced with the indirection operator

A

false

26
Q

[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.

A

true

27
Q

[T/F]

The address operator is not needed to assign an array’s address to a pointer

A

true

28
Q

[T/F]

You can change the address that an array name points to

A

false

29
Q

[T/F]

Any mathematical operation, including multiplication and division, may be performed on a pointer

A

false

30
Q

[T/F]

Pointers may be compared using the relational operators

A

true

31
Q

[T/F]

When used as function parameters, reference variables are much easier to work with than pointers

A

true

32
Q

[T/F]

The new operator dynamically allocates memory

A

true

33
Q

[T/F]

A pointer variable that has not been initialized is called a null pointer

A

false

34
Q

[T/F]

The address 0 is generally considered unusable

A

true

35
Q

[T/F]
In using a pointer with the delete operator, it is not necessary for the pointer to have been previously used with the new operatior

A

false