Test your Knowledge of C++ Language Features


Gensen Huang
Idyllic Icon

Gensen Huang

Created 6/19/2024

54

67.69%

Q & A


Share This Quiz

Sources

https://oleksandrkvl.github.io/2021/04/02/cpp-20-overview.html

Think you know everything about C++? Take this quiz and find out how many correct answers you can get out of 20!

Think you know everything about C++? Take this quiz and find out how many correct answers you can get out of 20!

1. What feature allows more explicit [=, this] captures in lambdas?

[[no_unique_address]]
Three-way comparison
Lambda expressions
Conditionally explicit constructors

2. What new keyword enforces compile-time initialization of variables?

constinit
constexpr
consteval
const

3. Which type was introduced to distinguish UTF-8 encoded strings?

char
char8_t
wchar_t
uchar_t

4. Which keyword allows coroutines to return a value?

co_await
co_yield
return
co_return

5. What comparison operator can be defaulted similarly to special member functions?

<
<=>
==
!=

6. Which concept allows specifying default initialization within constexpr functions?

Trivial default initialization
Trivially copyable
Conditionally explicit constructors
Immediate functions

7. Which type of object creation allows variables to begin their lifetime implicitly?

Class types with trivial constructors
Structs with virtual functions
Arrays of static size
Plain old data types

8. What macro expands to nothing if __VA_ARGS__ is empty?

__VA_ARGS__
__VA_EXPR__
__EMPTY__
__VA_OPT__

9. Which feature ensures all signed integers are represented in two's complement?

consteval
constinit
signed integers standardization
implicit move semantics

10. What attribute indicates a member doesn’t need a unique address?

[[nodiscard]]
[[likely]]
[[no_unique_address]]
[[unlikely]]

11. Which keyword can be used for variable declarations to be scoped to a single logical unit instead of being header-file based?

Modules
Noexcept
Singletons
Template

12. What feature allows destructors for built-in types to now have an effect?

std::destroying_delete_t tag
pseudo-destructor
noexcept
co_return

13. In C++20, how are stateless lambdas different?

They can be captured by reference only
They are automatically constexpr
They are default constructible and assignable
They require explicit type naming

14. Which attribute can now be applied to constructors similar to [[deprecated]]?

[[discard]]
[[nodiscard]]
[[likely]]
[[no_unique_address]]

15. What is the purpose of the constinit keyword?

To allow constant initialization only for constexpr variables
To enforce initialization at compile-time
To ensure initialization at run-time
To deprecate initialization of certain variables

16. Which feature allows floating-point and class types as template parameters?

Modules
Concepts
Scoped enums
Template metaprogramming

17. Which feature indicates conversion from T* to bool is now narrowing?

Implicit move semantics
T* to bool conversion
volatility contexts
Static initialization order

18. What central keyword feature allows the invocation of coroutines in C++20?

constexpr
noexcept
co_await
structured binding

19. What is the new type that helps with handling different encodings by their type?

u8char_t
char8_t
wchar_t
u32char_t

20. Which attribute helps to optimize space occupation by non-static non-bitfield data members?

[[no_unique_address]]
[[likely]]
[[nodiscard]]
[[deprecated]]