Programming Concepts Flashcards
(15 cards)
Give code to make a dynamic array in C++. Then the code to delete it.
int size; Double *arrayName; cin >> size; arrayName = new double[size]; delete [ ] arrayName;
Name a Unix editor. Two if you can.
Vi. Another acceptable answer is PICO.
What is a dangling pointer in C++? Show code to illustrate.
Where ptr1 points to ptr2. Then ptr2 gets deleted. *ptr1 = new Node; *ptr2 = new Node; ptr1 = ptr2; delete ptr2;
What is a memory leak? Give code to illustrate.
It is where dynamic data becomes inaccessible due to someone not deleting something properly. *ptr1 = new Node; *ptr2 = new Node; ptr1 = ptr2; delete ptr2; // ptr1 is now inaccessible
What is Putty or SSH?
It is a program used to connect to a remote Unix system.
In recursion, what are the two minimal things necessary?
Base Case: A case where the answer is known.
General Case: The recursive algorithm that changes/looks at something then calls itself.
What’s the difference between passing by reference and passing by value?
Pass by Value: This COPIES the variable being passed into the function. The variable itself is not altered.
Pass by Reference: This passes the actual variable itself into the function and therefore will be altered elsewhere.
What is a copy constructor and when are they typically used?
A copy constructor is called whenever a deep copy needs to be made (passed by reference). This is typically used in arrays, vectors and dynamic data.
What is a deep copy?
It makes a Copy of the entire variable. All the data members, pointers, and arrays.
Using the class “Person” give the code for overloading the + operator.
const Person operator+(const Person& obj)
What is polymorphism?
The reclassification of code based on the the circumstances. The code will behave differently depending on different contexts.
Give a few examples of polymorphism.
Inheritance
Operator Overloading
Virtual Functions
What is a virtual function?
A virtual function is a generalization of a function. Virtual functions are usually overridden, and pure virtual functions MUST be overridden.
What is the advantage of using exceptions in your code?
If you want to catch a problem in your code you just throw an exception. This allows you to handle the exception somewhere other than where it occurred.
Make the template and header code for a function “Print” that passes a template value T named val.
template void Print( T val ){ }