An inventory simulation uses the following C function. Each units member records a number of items. Treat the two scenarios below as independent runs, and report all three requested final counts as exact integers in items.
struct Stock { int units; }; void redistribute(struct Stock *source, struct Stock *destination, struct Stock opening) { source->units -= opening.units / 4; destination->units += opening.units / 4; source->units += destination->units / 10; }
In the shared-object scenario, the call is:
struct Stock bin = {160}; redistribute(&bin, &bin, bin);
In the separate-object scenario, the call is:
struct Stock reserve = {160}; struct Stock shelf = {60}; redistribute(&reserve, &shelf, reserve);
Find the final count in bin for the shared-object scenario, then the final counts in reserve and shelf for the separate-object scenario. All divisions in these runs have exact integer results.
Unlock full course notes by signing up
Following a reassigned pointer parameter
An inventory program runs the following C code. Find the final values of a.units and b.units immediately before main returns. Report both quantities in inventory units as exact integers, to zero decimal places.
Qualifying the addressed structure
A reporting function receives a pointer to a structure whose only member is an integer count. Its interface should prevent direct member assignments through that pointer while allowing the function to reassign its local pointer parameter. Place the C keyword ________ immediately before struct Sample in the parameter declaration.
Following counts stored inside a structure
A packing program stores two item counts inside a structure. Trace the following C code and complete the table at the two indicated checkpoints. Enter exact integer counts without units.
Both count columns refer to the caller's variable batch, and the result column refers to the caller's variable result.
Tracing shared data through a copied structure
A C program stores a record count and a pointer to an external integer in a structure. After the following code executes, which statements are true immediately before main returns? Select all that apply.