auto, range-for, move semantics, constexpr, structured bindings, std::optional, std::variant, modules, coroutines and the spaceship operator.
40 cards · basic cards · AI-written, checked twice. Edit anything.
- What does auto do in C++11?
Show answer
Deduces the type of a variable from its initializer
- Can you use auto with function return types in C++14?
Show answer
Yes, a function can return auto and the return type is deduced from return statements
- What is the type of x in: auto x = 5;
Show answer
int
- What happens if auto is used for a variable with no initializer?
Show answer
Compile error; auto requires an initializer to deduce the type
- What C++ version introduced range-based for loops?
Show answer
C++11
- What is the syntax for a range-based for loop?
Show answer
for (type element : container) { ... }
- What does a range-based for loop require from a container?
Show answer
begin() and end() member functions, or external begin/end functions in the same namespace
- What is an rvalue reference in C++11?
Show answer
A reference to a temporary object, declared with &&
- What is the difference between copy and move semantics?
Show answer
Copy creates a new independent copy; move transfers ownership of resources to avoid duplication
- What keyword forces move semantics when passing an lvalue?
Show answer
std::move
- What is a move constructor?
Show answer
A constructor that takes an rvalue reference and transfers resources from the temporary
- Can you call a move constructor with an lvalue?
Show answer
Only if you explicitly use std::move to cast it to an rvalue reference
- What does constexpr mean in C++?
Show answer
The expression or function can be evaluated at compile time to produce a constant
- Can a constexpr function also run at runtime?
Show answer
Yes, if the inputs are not compile-time constants, the compiler generates runtime code
- What is consteval (C++20)?
Show answer
A function that must always be evaluated at compile time, never at runtime