Quiz 2 Flashcards
Exceptions
allows program to catch and handle errors
Exception handler
allows program to recover through a try-catch
Stack memory
for data that is automatically managed or statically allocated at runtime
Heap memory
for data that is dynamically allocated
Casting
taking one type of data and converting it to another
broad: how bits are interpreted
Explicit Ctors
turns off implicit conversions
Implicit Ctors
can be overwritten with diff data types (compiler adds code to cast to a different type)
Pointers
contains memory address as value
must be defined
* to dereference
References
applied to a variable to access the address
cannot be null
require initialization
cannot change what it refers to
must be const if initialized with literal value
Const
ensures data cannot be modified
makes temp variables when unnamed/not matching the type
this
non-const member function: X * const
- const pointer to a non-const object X
const member function const X * const
- object is also const
Static Memory
Reserved at compile-time, allocated when the program starts and deallocated when it ends. Ex. Global variables, static variables in functions, static class members.
Dynamic Memory
Allocated on the program’s heap during run time. Requires new and delete operators. Examples: When memory is allocated for an array.
Automatic Memory
Allocated on the program’s execution stack during run time, as control flow enters and deallocated as flow exits from a block of code
Ex. Function parameters, local variables, and functions
Try block
encloses code that may generate error/ produce an exception