0% found this document useful (0 votes)
3 views

cpp_technical_mcq

The document contains a series of advanced C++ technical multiple choice questions covering topics such as class templates, smart pointers, complexity guarantees, and the Rule of Five. Each question includes four answer options, with the correct answer indicated. Key concepts such as std::move, std::lock_guard, SFINAE, and noexcept are also addressed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

cpp_technical_mcq

The document contains a series of advanced C++ technical multiple choice questions covering topics such as class templates, smart pointers, complexity guarantees, and the Rule of Five. Each question includes four answer options, with the correct answer indicated. Key concepts such as std::move, std::lock_guard, SFINAE, and noexcept are also addressed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Advanced C++ Technical Multiple Choice Questions

1. Which of the following ensures a class template member function is only instantiated for integral types?
A. template<typename T> void f() requires std::is_integral_v<T>;
B. template<typename T, std::enable_if_t<std::is_integral_v<T>, int> = 0> void f();
C. template<typename T> void f() if_integral<T>();
D. template<typename T> requires Integral<T> void f();
Answer: B

2. What does the expression std::move(x) do?


A. Performs a deep copy of x
B. Casts x to an rvalue reference
C. Deletes x
D. Moves x to a new memory location
Answer: B

3. Which smart pointer allows multiple owners of the same resource?


A. std::unique_ptr
B. std::auto_ptr
C. std::shared_ptr
D. std::weak_ptr
Answer: C

4. What is the complexity guarantee of std::vector::push_back when reallocation is needed?


A. Amortized constant time
B. Always constant time
C. Linear time for each call
D. Logarithmic time
Answer: A

5. Which of the following is NOT part of the Rule of Five?


A. Copy constructor
B. Move constructor
C. Destructor
D. Virtual constructor
Answer: D

6. What is the value of constexpr function call at compile time?


A. It’s always computed at runtime
B. Computed at compile time if arguments are constexpr
C. Only works for integral types
D. Cannot throw exceptions
Answer: B

7. How does std::lock_guard differ from std::unique_lock?


A. lock_guard can be unlocked manually
B. unique_lock is non-copyable
C. unique_lock allows deferred locking and unlocking
D. lock_guard supports move semantics
Answer: C

8. What is SFINAE in C++?


A. Standard Failure Initialization And Enumeration
B. Substitution Failure Is Not An Error
C. Simple Function Inlining And Evaluation
D. Safe Function Invocation And Exception
Answer: B

9. Which header provides std::tuple and std::apply?


A. <utility>
B. <tuple>
C. <algorithm>
D. <functional>
Answer: B

10. What guarantee does std::vector<T>::data() provide?


A. Returns pointer to null-terminated array
B. Iterator invalidation on push_back
C. Contiguous storage of elements
D. Always aligned to 16 bytes
Answer: C

11. Which atomic operation orders other memory operations around it?
A. std::atomic_thread_fence
B. std::atomic_init
C. std::atomic_exchange
D. std::atomic_store
Answer: A

12. What does the noexcept specifier do when applied to a function?


A. Prevents throwing exceptions at compile time
B. Marks that the function will not throw exceptions
C. Converts exceptions into error codes
D. Enables faster inlining
Answer: B

You might also like