Pointers and References (5) Flashcards

1
Q

What are Automatic conversions?

A

Compiler adds code necessary to create code to automatically convert the value.
When value passed in does equal the param value –> forces it in

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

What does the explicit keyword do?

A

Turns off automatic/ implicit conversion

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

What does const do?

A

Ensures that the data cannot be modified

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

What is a pointer?

A

Variable that contains a memory address as its value
Must be defined before use
Dereference using *

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

What is &?

A

Address operator

Applied to a variable to access the address

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

What is a reference?

A

Another name for an existing object

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

What are the major differences between pointers and references?

A

1) no null references
2) all references require initialization when declared
3) a reference always refers to the object with which it is initialized

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

What is a reference to a const being initialized with a literal mean?

A

Usually you cannot set a reference = a literal (a value)

If you say const then it creates an unnamed temp variable

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

What is pass-by-value?

A

Creates a copy of the data

Only copy is modified

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

What is pass-by-reference

A

Allows original data to be modified

Uses references in func call

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

How does a func call with const references behave?

A

Behaves like passing-by-value

Creates temporary variable

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

Const pointer vs pointer to const?

A

If const is on the right side of * –> pointer is const

If const is on the left side of * –> pointer is pointing to a const

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

What type is this in a non-const member function?

A

X* const

Object to which this refers to can be modified

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

What type is this in a const member function?

A

const X * const

Object cannot be modified

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

What is the advantage of returning a reference to a const object instead of the object?

A

Returning ref does not invoke copy ctor

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