Skip to main content

Practice · 2 of 3

Fix: Unguarded Input

CHALLENGE
Difficulty: beginner+25 XP

safe_div(int a, int b) crashes on b == 0 (and on a NULL result slot). Fix it to return 1 and write the quotient on success, or 0 and leave *out untouched when b == 0 or out == NULL. ``c int safe_div(int a, int b, int *out) { *out = a / b; return 1; } ``

Back to lesson: Practice: Crash Forensics