Practice ยท 1 of 4
Ownership Transfer Protocols
Implement the three transfer flavors:
``c
/* STORE: copies s into the slot; caller keeps ownership of its own copy. */
void store_copy(char **slot, const char *s);
/* TAKE: slot now owns s's memory (no copy). Caller must not free s. */
void take_ownership(char **slot, char *s);
/* RELEASE: hands ownership back; returns the pointer and empties the slot. */
char *release(char **slot);
``
NULL-safe throughout: any NULL argument is a no-op (release returns NULL).
Difficulty: intermediate
Press Submit to check your solution.
Back to lesson: Practice: Ownership Patterns Gym