Test Your C++ Knowledge with the Ultimate UB Quiz

Your Result:

Great

adaptablebastio

Idyllic Logo
score thumbnail
Idyllic Logo

created on us.idyllic.app

75% correct (15/20)

Scroll down to see answers

Idyllic Logo

created on us.idyllic.app

Scroll down to see answers

Rate this Quiz!

Share This Result

Comments

Idyllic Logo

created on us.idyllic.app

New Quizzes & Global Leaderboard Daily

Quiz Leaderboard

adaptablebastio

6/20/2024

75%

Answers

1. What does UB stand for in C++?

Undefined Behavior
Unbounded Buffer

2. Which of the following is NOT a cause of UB in C++?

Array index out of bounds
Valid memory allocation

3. What can UB lead to in a program?

Crashes or unexpected behavior
Compiling errors

4. Accessing a null pointer in C++ results in?

Undefined Behavior
Defined Behavior

5. Dereferencing an invalid iterator in C++ causes?

Undefined Behavior
Memory Leak

6. Using an uninitialized variable in C++ can lead to?

Undefined Behavior
Compile-time warning only

7. Does integer overflow cause UB in C++?

Yes, it can lead to UB
No, it always results in a specific wrap-around value

8. What happens when a program divides by zero in C++?

Undefined Behavior
Exception thrown

9. Modifying a const object in C++ results in?

Undefined Behavior
Compilation Error

10. Which of the following can lead to UB?

Violating type-aliasing rules
Assigning a new value to a var

11. Calling a deleted function in C++ leads to?

Undefined Behavior
Compilation Error

12. Does using a pointer after it has been deleted cause UB?

Yes, it causes UB
No, it is safe

13. Are out-of-bounds array accesses considered UB?

Yes, they result in UB
No, they are caught at compile-time

14. What does reading from a union member other than the last one written to lead to in C++?

Undefined Behavior
Compiler-dependent behavior

15. Is calling a virtual function from a destructor UB?

Yes, it can cause UB
No, it is always safe

16. Using an object after it has been moved from can lead to?

Undefined Behavior
Defined behavior if using std::move

17. Accessing a member of a structure through a differently-typed pointer variable causes?

Undefined Behavior
No problems, fully allowed

18. Which of the following does NOT result in UB?

Using a properly initialized STL container
Double free on dynamic memory

19. Reinterpreting a pointer of one type to another incompatible type leads to?

Undefined Behavior
Valid pointer conversion

20. Is modifying a const object through a const_cast defined behavior?

No, it results in UB
Yes, it is defined behavior