link* next_marked_link = list; // a temp variable to keep track // the following lines loop through the linked list until a NULL link is reached for (link* marked_link = list; marked_link != NULL; marked_link = marked_link->next) { delete marked_link; // the delete function releases memory for you. }


Arrays are a more basic way to store information. Suppose you want to keep track of the population of each of the 50 states in the US. You could create 50 variables, 1 per state and give each a different name, to keep track of the information. A far better way to do so would be to create an array:

long State_population[50];

This keeps all the information together, and makes it much easier to keep track of variables. You can then assign values to the array elements:

State_population[4] = 3; // State #4 has 3 people

The number in brackets is called the index of the array. State_population[] has 50 elements, so you can use indices from 0 up to 49 to access its elements (arrays are "zero-indexed", meaning that the first spot is index zero, not index one). Trying to access State_population[50] would give an "array out of bounds" error and probably crash your program.

If you know all the values for an array at the time of declaration, you can define it immediately:

int Days_in_month[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

Notice there is no number between the square brackets. This is an option, although for clarity's sake you can include it.

Arrays can have multiple dimensions. To create an array that represents a 3x3 matrix, you could type: