0% found this document useful (0 votes)
3 views1 page

Test4 C++

The document contains a series of multiple-choice questions related to advanced C++ concepts, including type erasure, strict aliasing rule, two-phase lookup, std::enable_if, and move semantics. Each question presents options that test the reader's understanding of these topics. The focus is on key features and benefits of C++ programming practices.

Uploaded by

andrewtate2136
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Test4 C++

The document contains a series of multiple-choice questions related to advanced C++ concepts, including type erasure, strict aliasing rule, two-phase lookup, std::enable_if, and move semantics. Each question presents options that test the reader's understanding of these topics. The focus is on key features and benefits of C++ programming practices.

Uploaded by

andrewtate2136
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

1. What is “type erasure” in C++ commonly used for?

a) Hiding the implementation details of a class behind an abstract base


b) Allowing objects of different types to be stored and invoked through a single uniform
interface at runtime
c) Eliminating the need for header files by generating code at compile time
d) Preventing the use of virtual functions in performance-critical code

2. What does the “strict aliasing rule” enable the compiler to assume?
a) That pointers of different types will never point to the same memory location (unless
explicitly allowed), enabling better optimizations
b) That casts between unrelated pointer types always perform a byte-wise copy
c) That all objects must be aligned to their natural boundaries to avoid misaligned accesses
d) That pointer arithmetic wraps around at the end of an array

3. What is “two-phase lookup” in the context of C++ templates?


a) A compile-time mechanism where dependent names are looked up in two separate stages:
once when the template is defined and again when it is instantiated
b) A runtime mechanism that delays overload resolution until the function is actually called
c) A debugging feature that prints template arguments during both definition and instantiation
d) A way to split header parsing into two passes for faster compilation

4. What role does std::enable_if play in C++ template metaprogramming?


a) It provides a way to generate compile-time error messages when template conditions fail
b) It conditionally includes or excludes overloads or specializations based on a compile-time
Boolean expression
c) It automatically selects the best matching overload based on argument conversions
d) It enforces that only integral types can be used with a given template

5. What is the primary benefit of “move semantics” in C++?


a) To allow objects to be partially copied while keeping the remainder uninitialized
b) To enable the transfer of resources (like heap memory) from one object to another without
performing a deep copy
c) To force all copy operations to go through std::move for safety
d) To convert lvalue references into rvalue references automatically at runtime

You might also like