c4 Flashcards

(15 cards)

1
Q

What does the indirection operator do?

A

Accesses the value stored at a memory address.

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

What will *arr display?

A

The first element of the array arr.

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

What will *arr + 2 display?

A

The first element plus 2.

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

What are three uses of the & operator?

A

Address-of, reference declaration, bitwise AND.

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

What math operations are allowed on pointers?

A

Addition and subtraction.

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

What happens when you add 4 to a pointer?

A

It moves forward 4 elements.

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

What does cout &laquo_space;*(numbers + 2) display?

A

The value at numbers[2].

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

What is the purpose of the new operator?

A

Dynamically allocates memory.

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

What happens if new cannot allocate memory?

A

Returns a null pointer (0 or nullptr).

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

How did older compilers handle memory allocation failure?

A

Returned a null pointer (0).

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

What is the purpose of the delete operator?

A

Releases dynamically allocated memory.

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

When can you return a pointer from a function?

A

When it points to valid memory like dynamic memory.

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

What is a pointer to a constant?

A

Pointer cannot modify the value it points to.

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

What is a constant pointer?

A

Pointer cannot point to a different address.

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

Two advantages of const pointer parameters?

A

Protects data from changes; allows use with const arguments.

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