Midterm Review Flashcards

1
Q

What does the new operator do?

A

Allocates memory for object of type to right of new and assign value to pointer to left of the word new

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

Roadster = new int;

A

allocates 4 bytes from heap to store an integer at an address that gets stored in pointer Roadster

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

What is a static array? example

A

int stat[10]; static and knows at compile time that space for 10 integers will be allocated

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

What is a dynamic array? example

A

cin»arraysize;
int* a;
a=new int[arraysize];
delete [] a; -> at compile and program startup, the amount of space for the array is indeterminant; when the cin runs, the user sets the size; now set for lifetime of program

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

What is heap?

A

Heap is a system managed binary tree of available memory.

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

How does pointer relate to heap?

A

If you declare a pointer variable and then new it, sufficient memory space is given up from the heap for a variable of the type the pointer points to.

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

How does delete relate to heap and pointers?

A

When delete is executed, the memory used that is pointed to by the pointer in the delete is returned to the heap tree.

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

In what sense are linked lists more dynamic than dynamic arrays?

A

With linked lists (and trees) memory is allocated/deleted from/back to the heap as needed throughout the program’s life. With dynamic arrays, once the memory is first allocated its size is permanent throughout program life

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

What does *pointer mean?

A
  • is de-reference; value at variable pointed to by pointer; cout«*pointer; prints out value at location pointed to by pointer.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What does & do with pointers?

A

p=&number1; sets pointer p to the address of the variable called number1

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

Explain when you use . and when you use :: with respect to member functions.

A

use . when invoking function in calling program i.e. classobj.function(); use :: only in implementation file when coding how the function runs;

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

What does :: have to do with “scope”?

A

the :: specifies the function name (identifier) will apply only in programs or functions that call it for an object of the class to the left of ::

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

How is a constructor named? How is it different from other methods? Explain what is meant with overloading constructor def.

A

constructor method has same name as the class itself. all other methods must have other names; overload constructors creates several versions for different numbers and types of input parameters.

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

what operations are more efficient with linked lists rather than arrays?

A

SORTING: to swap 2 records requires only changing a few pointers rather than moving all the data values of 3 records. adding and deleting records also require only pointer changes, not moving large sets of data.

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

Explain the difference between complexity O[N^2} and complexity O[2^n}. Examples and spaghetti

A

n^2 is quadratic: quadruples, bubble sort insertion sort; 2^n is exponential doubles in size, towers of hanoi; spaghetti is linear

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

What operations are more efficient with arrays than with linked lists?

A

search: fasst binary search vs slow sequential search(no names for most elements, can’t split)

17
Q

merge sort complexity

A

nlogn

18
Q

What is dynamic: arrays or linked lists?

A

linked lists; arrays are pseudo dynamic

19
Q

class

A

data type

20
Q

why ; after struct

A

can define structure variables in between } and ; ie struct dog {sejfojeifjoseijf} poodle, pug;

21
Q

constructor

A

has same name as class; called automatically when an object of the class is declared; initialize objects