Pointers and References (5) Flashcards
What are Automatic conversions?
Compiler adds code necessary to create code to automatically convert the value.
When value passed in does equal the param value –> forces it in
What does the explicit keyword do?
Turns off automatic/ implicit conversion
What does const do?
Ensures that the data cannot be modified
What is a pointer?
Variable that contains a memory address as its value
Must be defined before use
Dereference using *
What is &?
Address operator
Applied to a variable to access the address
What is a reference?
Another name for an existing object
What are the major differences between pointers and references?
1) no null references
2) all references require initialization when declared
3) a reference always refers to the object with which it is initialized
What is a reference to a const being initialized with a literal mean?
Usually you cannot set a reference = a literal (a value)
If you say const then it creates an unnamed temp variable
What is pass-by-value?
Creates a copy of the data
Only copy is modified
What is pass-by-reference
Allows original data to be modified
Uses references in func call
How does a func call with const references behave?
Behaves like passing-by-value
Creates temporary variable
Const pointer vs pointer to const?
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
What type is this in a non-const member function?
X* const
Object to which this refers to can be modified
What type is this in a const member function?
const X * const
Object cannot be modified
What is the advantage of returning a reference to a const object instead of the object?
Returning ref does not invoke copy ctor