Exam 2 Terms Flashcards
Dynamic Memory Allocation
Memory that is allocated during runtime. The memory is allocated on a heap data structure, and relies on pointers to access the information
Dynamic Memory Allocation (Usage)
Sometimes we don’t know the size of memory that we need, sometimes memory usage is limited
Dynamic Memory Allocation (Syntax)
New - allocated a new memory pointer
Delete - frees the desired allocated memory
Pointer memory allocation
Allocating memory using a pointer. (Done using the keyword “new”)
Ad Hoc polymorphism
Defining multiple functions with the same name, but changing their context (parameters). AKA - function overloading and operator overloading
General polymorphism
The ability for an object or a function to behave differently
Function output
the returned value after a function has been executed
Function overloading
multiple functions that have the same key signature (name) but have at least ONE different parameter, and the return value can be different
Operator overloading
Giving custom behavior to already defined operators. These only work with objects of a specified class
Friend functions
Have access to private and protected members of a class
Friend functions (drawbacks)
It breaks encapsulation, and data hiding, these are key pillars of OOP
What will you do if the list is empty and you want to add an item?
Using the object passed in, or by creating a new one, the firstPtr is set to the object, and the nextPtr and lastPtr are still pointing to the nullptr
What will you do if you want to add at the end of the list?
The object currently at the end of the list’s nextPtr is now pointing to the new object, and the new object is pointing to nullPtr
What will you do if you want to add at the first of the list?
The object we’re sending in nextPtr is set to point at the first object, and then we set the firstPtr to point to the new object we sent in
What will you do if you want to add before a given index?
Iterate across the list until you reach the desired index, then go back an object to insert the new object