Skip to main content

Practice · 1 of 4

Ownership Transfer Protocols

CHALLENGE
Difficulty: intermediate+25 XP

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).

Back to lesson: Practice: Ownership Patterns Gym