In-class C pointer exercises. If not finished, will be due as homework.
- Define a structure.
- Declare a static array of structures, outside of any function. What is the type of the array variable?
- Sketch the array on the worksheet.
- Assign values in a loop.
- Step through the code with the debugger.
- Define a structure.
- Declare a static array of structures, inside a function. What is the type of the array variable?
- Sketch the array on the worksheet.
- Assign values in a loop.
- Step through the code with the debugger.
- Define a structure.
- Allocate a dynamic array of structures. What is the type of the array variable?
- Sketch the array on the worksheet.
- Assign values in a loop.
- Free all dynamic memory.
- Step through the code with the debugger.
- Define a structure.
- Allocate a dynamic array of pointers to structures. What is the type of the array variable?
- Sketch the array on the worksheet.
- Assign values in a loop.
- Free all dynamic memory. Mind the order to avoid leaving dangling pointers!
- Step through the code with the debugger.
- Declare a node structure for a singly-linked list, holding a single
int
value. - Declare the list's
head
andtail
pointers. - Initialize the linked list. What does an empty list look like?
- Reason out the different assignment cases for the
list_insert
function. The nodes have to be inserted in ascending order. How should the pointer member of the node structure be initialized by default? - Implement the
list_insert
function, for all cases you came up with. - Test the function for all the cases. Run in the debugger to see if it works. Correct it.