Mixed Deck — All CPP Topics Flashcards
100 cards from real CPP practice questions. Tap to flip, then mark Knew It or Still Learning — missed cards come back until you master them.
Read the first 20 Mixed Deck — All CPP Topics flashcards as text
What is a CMake `INTERFACE` library primarily used for?
Answer: Propagating usage requirements (includes, defines) to consumers without compiling any sources
An INTERFACE library has no compiled output but can carry properties like include paths and compile options that propagate to linking targets.
What is a key principle of performance optimization & profiling in C++ Programming Professional Certificate practice?
Answer: Applying structured methodologies based on evidence and best practices
Performance Optimization & Profiling in C++ Programming Professional Certificate practice requires applying structured, evidence-based methodologies while adapting to specific professional contexts.
In C++20 modules, what is the effect of `export module mymodule;` at the top of a file?
Answer: Declares the file as the module interface unit for mymodule
export module mymodule; declares the file as mymodule's primary module interface unit, where exported declarations become visible to importers.
In a producer-consumer pattern using `std::atomic`, why might `memory_order_release` on the store and `memory_order_acquire` on the load be preferred over `memory_order_seq_cst`?
Answer: Release-acquire is sufficient to establish happens-before and avoids the global ordering overhead of seq_cst
A release store paired with an acquire load establishes the necessary happens-before relationship at lower cost than `seq_cst`, which requires a global total order across all threads.
When the `explicit` keyword is applied to a conversion operator, what effect does it have?
Answer: The conversion requires an explicit cast rather than happening implicitly
An `explicit` conversion operator (e.g., `explicit operator bool()`) means the conversion only happens with a direct cast, preventing unintended implicit conversions.
What is the conventional return type for the copy assignment operator (operator=)?
Answer: T&
The assignment operator should return `T&` (reference to *this) to support chaining such as `a = b = c`.
What is 'branch misprediction' and why is it costly?
Answer: Executing a branch before its condition is evaluated, sometimes incorrectly; costs a pipeline flush and refetch
When the CPU speculatively executes the wrong branch, it must flush the pipeline and restart from the correct path, wasting 15-20+ cycles on modern CPUs.
How does performance optimization & profiling contribute to professional excellence in CPP certification?
Answer: It enhances competency, improves outcomes, and supports continuous professional growth
Performance Optimization & Profiling is integral to CPP professional excellence, directly enhancing competency and driving measurable improvement in practice outcomes.
What is C++ name mangling?
Answer: The compiler encoding of a function's full signature into its binary symbol name
Name mangling encodes the full function signature (including parameter types) into the binary symbol name to support function overloading.
Which of the following is NOT a valid use of catch(...)?
Answer: Accessing the caught exception object's members
catch(...) catches any exception but provides no named object, so you cannot access the exception's members without rethrowing and catching by type.
What does the C++17 structured binding `auto [x, y] = std::make_pair(1, 2.0);` deduce for `x` and `y`?
Answer: x is int, y is double
Structured bindings decompose the pair preserving each element's original type, so x is int and y is double.
What does `auto` as a template parameter in C++17 non-type parameters enable?
Answer: Deduction of the non-type parameter's type from the supplied value
C++17 allows `template` so the type of the non-type parameter is automatically deduced from the provided constant value.
What is a 'fold expression' introduced in C++17 for variadic templates?
Answer: A compact syntax to apply a binary operator to all elements of a parameter pack
Fold expressions allow applying operators like `+` or `&&` across all pack elements, e.g., `(args + ...)` sums the pack.
What is the output of: int arr[3] = {10,20,30}; int* p = arr; std::cout << *(p+2);
Answer: 30
p+2 advances the pointer by 2 integer positions, pointing to the third element (30), and dereferencing it yields 30.
Which function template in reorders elements so those satisfying a predicate come first?
Answer: std::partition
std::partition reorders a range so elements satisfying the predicate precede those that don't.
What is the purpose of the 'mutable' keyword on a class data member?
Answer: It allows the member to be modified even inside a const member function
A mutable member can be modified by const member functions, which is useful for caches, mutexes, or lazy-computed values.
What does `std::format("{:>10}", "hi")` produce in C++20?
Answer: " hi" (right-aligned in a field of width 10)
> in the format spec means right-align; the string is padded with spaces on the left to fill a width-10 field.
Which of the following operators MUST be overloaded as a member function?
Answer: operator=
The assignment (=), subscript ([]), call (()), and arrow (->) operators must be defined as member functions per the C++ standard.
What is the role of `pkg-config` in a C++ build workflow on Linux?
Answer: It provides compile and link flags for installed libraries via `.pc` files
`pkg-config` reads `.pc` metadata files installed with libraries and outputs the correct `-I` and `-l` flags for the compiler.
In C++17, `if constexpr (condition)` differs from regular `if` in that:
Answer: The discarded branch is not instantiated in templates
if constexpr discards the non-taken branch at compile time within templates, preventing instantiation of otherwise ill-formed code.