Why would we write a class? (three reasons)
Avoid repeating code
Control access of certain variables and functions
Encapsulation
Why would we pass by reference instead of by value for most complex objects?
Avoid making a copy, which takes up a lot of memory
The "new" keyword does this.
What is allocating memory on the heap?
These are the Big Three.
What are Copy Constructor, Assignment Operator, and Destructor?
What is the access order of a queue?
FIFO
(First in, first out)
The last step in the C++ program compilation process.
What is linking?
What is printed?
int b = 5;
int* a = &b;
cout << a << endl;
Memory address of b
What is the main difference between the stack and the heap?
The stack is memory that is managed automatically based on scope, while heap memory is allocated and deallocated manually
This feature is the reason why we don’t split template classes into .h and .cpp files.
What is the compiler?
With respect to pointers, what do the operators -> and * do?
-> allows you to access an object variable or function through a pointer to that object.
* dereferences a pointer, giving you access to the object
In this class, what are the sizes (in bytes) of a char, a short, an int, and a pointer?
char: 1
short: 2
int: 4
pointer: 4
What is the expected return type of an overloaded /=, where T is the type of an object?
T&
What are the three differences between linked lists and arrays?
Linked Lists are not random access, but arrays are
Linked lists are non-contiguous, but arrays are contiguous
Linked lists require more memory space than linked lists.
What does the static keyword do when applied to a) a function, and b) a class?
a) It allows a variable to live longer than the function
b) It creates a variable shared by all instances of a class
What is held constant in this function? What is returned?
int* const MyClass::func(const int* p) const;
The function has a const parameter and the object calling the function is held constant; the function returns a const pointer to an int.
Briefly explain how to insert a node into the middle of a singly Linked List.
First, iterate to one before where you want to insert the new node.
Then, point the new node’s next pointer to the current next node, and point the current node’s next pointer to the new node