How Well Do You Know C++ UB?
Put your knowledge of C++ Undefined Behavior to the test with this quiz!
Question 1 of 10How Well Do You Know C++ UB?
All 10 questions
- What does UB stand for in C++?Undefined Behavior · Uniform Binary · Unlimited Bounds · Universal Base
- Which of the following is a common cause of undefined behavior in C++?Using a smart pointer · Casting an int to a float · Dereferencing a null pointer · Using a for loop
- What can be a result of invoking undefined behavior in a C++ program?The program runs slower · The program could produce unpredictable results · The code will always give a compile-time error · The program uses more memory
- Which of the following operations on an integer can lead to undefined behavior?Addition · Subtraction · Division by zero · Multiplication
- Is it safe to modify a string literal in C++?Yes, it is safe · Yes, but only if the literal is not used again · No, it results in undefined behavior · No, it is safe but generally not recommended
- What happens when you access an array out of its bounds in C++?Nothing happens · It results in undefined behavior · The program catches an exception · You get a warning at compile time
- Which of the following is NOT a cause of undefined behavior?Reading uninitialized variables · Shifting bits by a negative amount · Correctly using unique_ptr · Accessing a dangling pointer
- Why is it important to avoid undefined behavior in C++ programs?It can make the code less readable · It can lead to non-portable code · It can introduce security vulnerabilities · It uses more CPU resources
- Which of these can lead to undefined behavior when using pointers?Initializing a pointer with nullptr · Dereferencing a null pointer · Assigning one pointer to another · Using a const pointer
- What is the recommendation to prevent undefined behavior related to type conversions in C++?Avoid using typecasting · Carefully use static_cast, dynamic_cast, etc. · Use only implicit type conversions · Ignore compiler warnings





