Exam 4 (CSC201)

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

How do you pass a pointer by reference?

&

Define a dynamic linked list

A dynamic linked list is one in which the nodes are linked together by pointers and an external pointer (or head pointer) points to the first node in the list

What is an inaccessible object?

An unnamed object created by operator new that a programmer has left without a pointer to it.

When is dynamic memory allocated?

At runtime, NOT compile time

What does delete intPtr do?

DEALLOCATES intPtrand - the object or array currently pointed to by the pointer is deallocated, and the pointer is considered unassigned. That deallocated memory is now sent to the heap for reuse

What does linear mean?

Each list element (except the first) has a unique predecessor, and Each element (except the last) has a unique successor

Where are new variables stored?

In the heap (free store), a pool of memory locations reserved for allocation/deallocation of dynamic data

What does the new keyword actually do?

It allocates space for the requested object or array and returns a pointer to (address of) the memory allocated.

What happens if a pointer points to a variable that no longer exists?

It becomes a dangling pointer

What happens if a dynamic variable no longer has a pointer pointing to it?

It becomes an inaccessible object

What does "delete intPtr" really do?

It deletes the value which intPtr points to, NOT the pointer itself. Also known as "deallocating," the memory is returned to the free store (heap).

What's a way of preventing inaccessible memory?

Make a pointer constant

It is an error to dereference a pointer whose value is what?

NULL

Difference between a reference type and pointer type

Reference type: Can only be initialized a variable's address Pointer type: Can be assigned a variable's address any number of times

TRUE or FALSE: Is it erroneous to dereference nullptr?

TRUE

What does intPtr2 return?

The address value stored in intPtr2

What does *intPtr1 return?

The value of the variable pointed to by intPtr1

How do you fix the "chicken and egg" definition issue?

Use a forward definition of the struct or whatever type of data

Dynamic array allocation

char *ptr;ptr = new char[ 5 ]; strcpy(ptr, "Bye"); ptr[ 1 ] = 'u'; // A pointer can be subscripted cout << ptr[ 2];

What happens when you copy a node's data to another node?

deep copy

Accessing a variable using an address stored in a pointer

direct addressing

What do you call a type of data structure that can expand and contract?

dynamic data structure

What is a linked structure whose nodes are dynamically allocated on the heap?

dynamic linked list

What do you call a pointer that points to the first node in a dynamic linked list?

external (head) pointer

Accessing a variable using its name

indirect addressing

What is a collection of nodes called?

linked list

What happens if you keep dynamic variables that are no longer needed?

memory leak

What happens when listOne = listTwo?

shallow copy

What do you call it when you go through a list?

traversal

Dynamic memory

variables created during program execution by means of special operations (new and delete)

How to traverse a list and print each component

while (ptr != NULL) { cout << ptr->info; // Or, do something else with node *ptr ptr = ptr->link; }


Set pelajaran terkait

Section 7 - Sales Comparison, Cost and Income Approaches

View Set

Among the Hidden Chapter 6-10 Review

View Set

Accounting Chapter 11 Review Questions

View Set