Master the fundamental concepts of c programming deep dive through this focused micro-challenge.
Undefined behavior means the C standard places no requirements on what happens next. Clang and GCC treat that as a license to optimize aggressively: a null check after a dereference may disappear because the compiler reasons the dereference could not have happened if the pointer were null. The Linux kernel's famous null-check elision bug came from exactly this assumption.
INT_MAX + 1 on a signed int is UB; unsigned wraps by definitionarr[5] on int arr[5] reads past the object; ASan catches it instantlybashLoading…
UBSan and ASan turn silent UB into loud crashes during development.
For this exercise, you will document six UB categories with commented-out dangerous lines and safe alternatives. This task asks you to explain each case in prose, because every serious C codebase runs sanitizers in CI and engineers still ship UB without understanding why the optimizer "broke" their check.
Create a program that demonstrates various undefined behaviors and explains why they're dangerous.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github