Explain Undefined Behavior and how it can impact program behavior in unexpected ways. Examples of Undefined Behavior. How compiler optimizations change program behavior in unexpected ways. Undefined Behavior (UB) is a fundamental concept in C and C++ that profoundly impacts program behavior and security. How one explains UB and compiler optimizations is essential when trying to code more securely.