1. Which of the following is NOT a feature of std::unique_ptr?
std::unique_ptr
unique_ptr
2. Which of the following is NOT a difference between deterministic problems in your code and non-deterministic problems?
3. If a class has at least one virtual function, which cast can use this information for safer downcasting?
dynamic_cast
static_cast
const_cast
reinterpret_cast
4. What happens if you use const_cast to cast away the constness of an object that was originally defined as const and then modify it?
const
5. A std::shared_ptr can use the same operators as a raw pointer (e.g., * or ->). How is this accomplished?
std::shared_ptr
*
->
shared_ptr
6. Which of the following debugging techniques is so time intensive that it should typically be attempted only after the other techniques fail to help you resolve the issue?
7. What does std::make_shared do?
std::make_shared
weak_ptr
8. Which of the following is **NOT** true about the relationship between unit testing and "higher level" tests (e.g., integration tests, component tests)?
9. For which of the following is static_cast NOT appropriate?
10. Which of the following is an example of undefined behavior in C++?
sizeof
size_t
return
void
11. Assume our API specifies the following integer exponentiation function declaration, and we have been asked to test it (this is a raised to the b power): int Exponentiate(int a, int b); Assuming the function declaration will not change, which of the following is not a useful test case?
a
b
REQUIRE(Exponentiate(-1, 3) == -1);
REQUIRE(Exponentiate(-1, 2) == 1);
REQUIRE(Exponentiate(2, -1) == 0.5);
REQUIRE(Exponentiate(3, 2) == 9);
REQUIRE(Exponentiate(3, 0) == 1);
12. When committing code that you have debugged, which of the following should be bundled with a fix to that code?
13. If you successfully compile your code, why might you still need to worry about syntax errors with this code?
14. When you create a std::unique_ptr you can provide a function to run on deletion. Why is this useful?
15. What will be the result of using reinterpret_cast to convert an integer pointer to a character pointer?
16. What do you need to do before a std::unique_ptr called ptr falls out of scope (assuming you are done with the pointed-to memory) to avoid memory leaks or corruption?
ptr
ptr.delete();
delete ptr;
ptr.reset();
17. What happens if you copy one std::shared_ptr to another?
18. Which of the following is NOT a productive development practice for preventing bugs in your code?
19. What happens when you run std::move() on a unique_ptr value?
std::move()
20. What is the advantage of a "time-traveling" debugger?
21. Which of the following is a valid definition of undefined behavior?
22. The following code snippet of a function contains undefined behavior. Identify the cause of undefined behavior and where it arises. Line 1) void MyFunction(){ Line 2) uint8_t x; Line 3) x += 10000; Line 4) return; Line 5) }
Line 1) void MyFunction(){
Line 2) uint8_t x;
Line 3) x += 10000;
Line 4) return;
Line 5) }
x
23. Why should you use std::make_unique instead of new when constructing a unique_ptr?
std::make_unique
new
24. If you trigger undefined behavior by writing outside the bounds of an array, which of the following results is possible according to the C++ standard?
25. Which if the following is NOT a reason that assertions are helpful in your code?
26. Which of the following is true about undefined behavior?
27. Which of the following reasons is NOT motivation behind unit testing?
28. What happens when the only two shared_ptrs pointing to an object both go out of scope?
Click Check Answers to identify any errors and try again. Click Show Answers if you also want to know which answer is the correct one.