Skip to main content

Practice · 2 of 4

Lifetime Violation or Not?

CHALLENGE
Difficulty: advanced+25 XP

Implement const char *lifetime_verdict(int kind) for five scenarios: 0 returning a pointer to a local → "dangling", 1 returning a malloc'd buffer → "valid", 2 storing a pointer to a stack array in a global → "dangling", 3 returning a pointer into a static buffer → "valid", 4 freeing then returning the freed pointer → "dangling".

Back to lesson: Practice: Detection Drills