Questions
C++ questions
Choose a question page, learn the concept, then test your understanding with a quiz.
Why Small Type Changes Can Change Performance in C++ Hot Loops
Learn why changing a loop counter type in C++ can drastically affect CPU performance, assembly output, and popcount benchmarks.
Why Sorted Data Can Make an if Statement Faster in C++: Branch Prediction Explained
Learn why sorted arrays can make conditional loops much faster in C++ by improving CPU branch prediction and reducing mispredictions.
Why Use static_cast in C++ Instead of C-Style Casts or T(x)?
Learn why C++ developers prefer static_cast over C-style casts, when T(x) is different, and how safer casting improves code clarity.
Why Variables Can't Be Declared Directly After a case Label in C++ switch Statements
Learn why C++ blocks variable declarations after case labels in switch statements and how to fix it with braces and scope.
Why Virtual Functions Matter in C++: Polymorphism Explained
Learn why virtual functions are needed in C++, how overriding really works, and when dynamic dispatch matters in inheritance.
Why `+ 0.1f` Can Be Faster Than `+ 0` in C++: Compiler Optimization and Floating-Point Behavior
Learn why changing `0.1f` to `0` can slow C++ code dramatically due to compiler optimizations, floating-point math, and loop removal.
Why `while (!stream.eof())` Is Wrong in C++ iostreams
Learn why `while (!stream.eof())` is a bug in C++ iostream loops, what to use instead, and how it compares to `scanf(...) != EOF` in C.
Why enum class Is Safer Than Plain enum in C++
Learn why C++ enum class is safer than plain enum, with type-safety examples, scoping rules, comparisons, and practical usage tips.
constexpr vs const in C++: What’s the Difference and When to Use Each
Learn the difference between constexpr and const in C++, when to use each one, and how compile-time constants differ from read-only values.
printf vs cout in C++: Output and Formatting Differences
Learn the difference between printf() and std::cout in C++, including formatting, type safety, headers, buffering, and when to use each.
push_back vs emplace_back in C++: What’s the Difference?
Learn the difference between push_back and emplace_back in C++, when each constructs or moves objects, and how to use them correctly.
std::distance vs Iterator Subtraction in C++
Learn when to use std::distance or iterator subtraction in C++, including complexity, iterator categories, safety rules, and vector indices.
std::endl vs \n in C++: Difference, Performance, and When to Use Each
Learn the difference between std::endl and \n in C++, when flushing happens, performance impact, and which one to use in real code.
std::forward in C++: Perfect Forwarding, Purpose, and Problems Solved
Learn why C++ std::forward preserves lvalue and rvalue arguments, how perfect forwarding works, and what changes when it is omitted.
std::map vs std::unordered_map in C++: Choosing the Right Associative Container
Learn when std::map can be preferable to std::unordered_map in C++, including ordering, complexity guarantees, iteration, memory, and safety.
std::string vs std::wstring in C++: Differences, Unicode, and When to Use Each
Learn the difference between std::string and std::wstring in C++, including ASCII, Unicode, wide characters, and when to use each.
std::unique_lock vs std::lock_guard in C++ Mutex Synchronization
Learn when to use std::lock_guard and std::unique_lock in C++, especially with mutexes, queues, and condition variables.
typename vs class in C++ Templates: What’s the Difference?
Learn the difference between `typename` and `class` in C++ template parameters, including nested templates and when `typename` is required.
Page 8 of 8 - 158 questions