From the course: Master C Language Pointers

Unlock the full course today

Join today to access over 22,500 courses taught by industry experts or purchase this course individually.

Removing structures

Removing structures - C Tutorial

From the course: Master C Language Pointers

Start my 1-month free trial

Removing structures

- [Instructor] Structures are managed in a linked list by manipulating their pointers. To remove a structure, the previous item in the list skips over it, referencing the following item. The structure is then unlinked or lost, and its memory freed. This exercise file creates a linked list of five items. The fill function at line 32 helps automatically build the list. In the main function the list is created in the for loop at line 62. The list is output at line 84. Starting at line 88, the fourth structure is removed from the list. This process involves adjusting the pointer stored in the third structure, which was now skip over the fourth structure and reference the fifth structure. The while loop at line 92 adjust the current pointer, so that it references the third structure in the list just before the structure to remove. The weird statement at line 104 copies the next pointer from the fourth structure in the list…

Contents