Programming Concepts Flashcards

(15 cards)

1
Q

Give code to make a dynamic array in C++. Then the code to delete it.

A
int size;
Double *arrayName;
cin >> size;
arrayName = new double[size];
delete [ ] arrayName;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Name a Unix editor. Two if you can.

A

Vi. Another acceptable answer is PICO.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a dangling pointer in C++? Show code to illustrate.

A
Where ptr1 points to ptr2. Then ptr2 gets deleted. 
*ptr1 = new Node;
*ptr2 = new Node;
ptr1 = ptr2;
delete ptr2;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is a memory leak? Give code to illustrate.

A
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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Putty or SSH?

A

It is a program used to connect to a remote Unix system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

In recursion, what are the two minimal things necessary?

A

Base Case: A case where the answer is known.

General Case: The recursive algorithm that changes/looks at something then calls itself.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What’s the difference between passing by reference and passing by value?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a copy constructor and when are they typically used?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a deep copy?

A

It makes a Copy of the entire variable. All the data members, pointers, and arrays.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Using the class “Person” give the code for overloading the + operator.

A

const Person operator+(const Person& obj)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is polymorphism?

A

The reclassification of code based on the the circumstances. The code will behave differently depending on different contexts.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Give a few examples of polymorphism.

A

Inheritance

Operator Overloading

Virtual Functions

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is a virtual function?

A

A virtual function is a generalization of a function. Virtual functions are usually overridden, and pure virtual functions MUST be overridden.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the advantage of using exceptions in your code?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Make the template and header code for a function “Print” that passes a template value T named val.

A
template
void Print( T val ){ }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly