

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!


int main() { int num; int *p, *q; p = new int; *p = 10; q = new int; *q = *p; q = p; delete p; delete q; // bad idea, q already deleted! q = NULL; // NULL is zero pointer, used as sentinel value
int main() { int *arr = new int[10]; for (int i = 0; i < 10; i++) arr[i] = i; delete[] arr; // delete[] if allocated with new[]
struct studentT { string first, last; string address, phone; }; struct courseT { string dept, name; Vector<studentT *> students; };
struct Entry { string name, address, phone; Entry *next; }; Each entry points to another Entry! Wired together, you get a linked list! name address phone next Rein 123 Pine 555- Kalev 204 Elm 555- Mati 89 Oak 555-
Entry *GetNewEntry() { cout << "Enter name (ENTER to quit):"; string name = GetLine(); if (name == "") return NULL; Entry *newOne = new Entry; newOne->name = name; cout << "Enter address: "; newOne->address = GetLine(); cout << "Enter phone: "; newOne->phone = GetLine(); newOne->next = NULL; // no one follows return newOne; }