Find storage lost through link changes

A C program initially owns five separately allocated nodes named A, B, C, D, and E. Each node has a next member, and sizeof(Node) is 24 bytes on this platform. The initial links are shown below.


Five separately allocated nodes named A through E form an initial chain from head to NULL.


The program executes these statements in order:


C
Node *keep = head->next->next;
Node *old = head;
head = head->next;
free(old);
old = NULL;
head->next = keep->next;
keep->next = NULL;
head = head->next;
free(keep);
keep = NULL;
head->next = NULL;


Assume there are no other program pointers to these nodes. At the end, how many requested bytes belong to nodes that remain allocated but cannot be reached by following next from any remaining program pointer? Exclude allocator bookkeeping and pointer-variable storage. Answer in bytes as an exact whole number.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

More Dynamic UDTs Questions: