Undefined behavior is when a program executes code for which the program language does not mandate any specific requirements. Basically, anything can happen, and it purely depends on what the compiler and the machine running the program do.
Some examples of undefined behavior is:
- Double free
- Dividing by zero
- Indexing out of bounds
Many are related to incorrect pointer usage:
int arr[4] = { 0, 1, 2, 3, 4 };
int *p arr + 5; //out of bounds UB
p = 0;
*p; //Null pointer dereference, UB