Pointers and references Flashcards

(9 cards)

1
Q

What is a pointer?

A

It is a variable that stores a memory address, the address of a another variable.

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

What is a reference?

A

It is an alias for an exisiting variable.

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

Explain pass-by-value and pass-by-reference

A

Pass-by-value means that a copy of the value is passed to the function, any modification stays within the function.
Pass-by-reference means that an alias is given to the function, any modification also affects the original variable.

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

What does an uninitialized pointer point to?

A

An uninitialized pointer points towards a “garbage” value, meaning towards an arbitrary memory location.

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

Can you reseat a reference?

A

No, once bound a reference cannot be changed to refer to another variable.

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

What does the the operator & do?

A

itr is the address-of operator, it returns the memory address of a variable.

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

What are pass by-reference and pass-by-pointer?

A

Pass by poinyret mean sending the memory location to the function while pass-by-reference means sending a reference variable of a varible. Since they are the same it allows us to modify the variable.

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

What are the differences between a pointer and a smart pointer?

A

A raw pointer does not express ownership, simply tells you the address and must be deleted manually.
A smart pointer deletes the memory once it goes out of bound, implies some forme of ownership and.

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