A C analysis routine begins with no dynamically allocated storage and performs these events in order. Every allocation and resize succeeds. An integer occupies 4 bytes and a double occupies 8 bytes. Ignore allocator overhead and any temporary internal storage used during resizing.
Complete the table with the total requested bytes in live allocations immediately after each stage finishes. Enter exact integers in bytes.
Unlock full course notes by signing up
Sequence a safe array-growth procedure
A C routine owns a live integer array through p and records its element capacity in capacity. It must grow the array to n elements, where n is positive and greater than capacity. All existing elements are initialized, and the required headers are included. The variables n, capacity, and bytes have type size_t, and tmp has type int *.
Arrange this procedure in execution order. The routine must check that the requested byte count is representable before performing the multiplication. A rejected size or failed resize exits the procedure while retaining the original array. The final initialization step must use the updated owning pointer p.
Evaluate resize guarantees and aliases
A C program has a live allocation for 9 integer elements, all initialized, and p points to its beginning. The program creates saved as an alias, another pointer referring to the same allocation, then executes this fragment. The requested byte count is positive and representable. Select every statement guaranteed by C's allocation rules.
Count the cost of a row-by-row grid
A function builds a grid of double values with rows = 6 and cols = 50, using one allocation for an array of row pointers and one allocation per row:
On this system sizeof(double) is 8 bytes and sizeof(double *) is 8 bytes. Count requested bytes only, ignoring any allocator overhead; a call that returns NULL reserves nothing. Give each answer as a whole number:
the bytes requested by the row-pointer allocation;