References and Pointers Flashcards
Compound / Composite Data Types
data types that can be constructed from fundamental data types or other compound data types
Value category of an expression
this indicates whether the expression resolves to a value, a function, or an object of some kind
lvalue
an expression that evaluates to a function or an object that has an identity (e.g. an identifier or an identifiable memory address)
two subtypes of lvalues
modifiable and non-modifiable
rvalue
an expression which is not an lvalue. Includes literals (except string literals) and return values of functions or operators when returned by value
reference
an alias for an existing object
once the reference has been defined, any operation on the reference is applied to the object being referenced
Two types of references in C++
lvalue references and rvalue references
lvalue reference
commonly called a reference
acts as an alias for an existing lvalue (such as a variable)
term for when a reference is initialized with an object or function
bound to it
referent
object or function being referenced by a reference
why are lvalue references occasionally called lvalue references to non-const
Lvalue references can’t be bound to non-modifiable lvalues or rvalues (otherwise you’d be able to change those values through the reference, which would be a violation of their const-ness)
references: reseated
Once initialized, a reference in C++ cannot be reseated, meaning it can not be changed to reference another object.
dangling reference
When an object being referenced is destroyed before a reference to it, the reference is left referencing an object that no longer exists.
Accessing a dangling reference leads to undefined behavior.
lvalue reference to a const value aka reference to const aka const reference
By using the const keyword when declaring an lvalue reference, we tell an lvalue reference to treat the object it is referencing as const.
Const references can bind to modifiable lvalues, non-modifiable lvalues, and rvalues.
temporary object / unnamed object / anonymous object
an object that is created for temporary use (and then destroyed) within a single expression.