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.
struct Buffer { int length; int *used; }; void revise(struct Buffer b, int *replacement) { b.length += 2; *b.used += 4; b.used = replacement; *b.used += 1; } int main(void) { int first = 20; int second = 30; struct Buffer original = {6, &first}; revise(original, &second); return 0; }
The caller's first becomes 24, while second becomes 31 after the call.
The caller's original.length remains 6 after the function call returns.
The caller's original.used still points to first, whose value remains 20.
The caller's original.used points to second after the function call returns.
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.
Updating one stock record through two parameters
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.
In the shared-object scenario, the call is:
In the separate-object scenario, the call is: