Test Your C++ Knowledge with the Ultimate UB Quiz
Think you know all about Undefined Behavior in C++? Take this quiz and find out how many correct answers you can score out of 20!
Question 1 of 20Test Your C++ Knowledge with the Ultimate UB Quiz
All 20 questions
- What does UB stand for in C++?Undefined Behavior · Unbounded Buffer
- Which of the following is NOT a cause of UB in C++?Array index out of bounds · Valid memory allocation
- What can UB lead to in a program?Crashes or unexpected behavior · Compiling errors
- Accessing a null pointer in C++ results in?Undefined Behavior · Defined Behavior
- Dereferencing an invalid iterator in C++ causes?Undefined Behavior · Memory Leak
- Using an uninitialized variable in C++ can lead to?Undefined Behavior · Compile-time warning only
- Does integer overflow cause UB in C++?Yes, it can lead to UB · No, it always results in a specific wrap-around value
- What happens when a program divides by zero in C++?Undefined Behavior · Exception thrown
- Modifying a const object in C++ results in?Undefined Behavior · Compilation Error
- Which of the following can lead to UB?Violating type-aliasing rules · Assigning a new value to a var
- Calling a deleted function in C++ leads to?Undefined Behavior · Compilation Error
- Does using a pointer after it has been deleted cause UB?Yes, it causes UB · No, it is safe
- Are out-of-bounds array accesses considered UB?Yes, they result in UB · No, they are caught at compile-time
- What does reading from a union member other than the last one written to lead to in C++?Undefined Behavior · Compiler-dependent behavior
- Is calling a virtual function from a destructor UB?Yes, it can cause UB · No, it is always safe
- Using an object after it has been moved from can lead to?Undefined Behavior · Defined behavior if using std::move
- Accessing a member of a structure through a differently-typed pointer variable causes?Undefined Behavior · No problems, fully allowed
- Which of the following does NOT result in UB?Using a properly initialized STL container · Double free on dynamic memory
- Reinterpreting a pointer of one type to another incompatible type leads to?Undefined Behavior · Valid pointer conversion
- Is modifying a const object through a const_cast defined behavior?No, it results in UB · Yes, it is defined behavior





