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.
The program executes these statements in order:
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.
Unlock full course notes by signing up
Track requested node storage
A monitoring program begins with six separately allocated nodes in a singly linked list. On this platform, each complete node occupies 32 bytes according to sizeof(Node).
The program successfully allocates and appends two additional nodes. Only after both additions are complete, it unlinks and frees three nodes. No other node allocations or releases occur.
Find the peak requested node storage during these operations and the final requested node storage. Give both answers in bytes as exact whole numbers. Exclude allocator bookkeeping and the storage of pointer variables.
Prepend without losing the existing list
A C function must prepend a reading of 105 to a singly linked list whose first node is identified by head. Each node has value and next members. The function uses a local pointer named candidate.
Arrange the procedure in its correct order. The function must leave the existing list unchanged if allocation fails and initialize the complete new node before replacing head.
Padding and the size of an allocated array of structs
A logger allocates its buffer of readings with calloc(50, sizeof(struct sample)). Two versions of the structure are being compared:
Assume a typical 64-bit Linux platform: char is 1 byte with alignment 1, int is 4 bytes with alignment 4, and double is 8 bytes with alignment 8. The compiler places members in declaration order and adds only the padding that alignment requires, including trailing padding so that sizeof is a multiple of the struct's largest member alignment.
Fill in each member's byte offset, the value of sizeof(struct sample), and the total bytes requested by the calloc call, as integers, for both versions.