Questions

C++ questions

Choose a question page, learn the concept, then test your understanding with a quiz.

What Is Move Semantics in C++? A Beginner-Friendly Guide

Learn what move semantics means in C++, why it matters, how move constructors work, and when moving is better than copying.

cppc++-faqc++11move-semantics

What Is Object Slicing in C++? Explanation, Examples, and How to Avoid It

Learn what object slicing means in C++, when it happens, why it is dangerous, and how to avoid it with references and pointers.

cppinheritancec++-faqobject-slicing

What Is std::move() in C++ and When Should You Use It?

Learn what std::move() does in C++, how move semantics work, and when to use std::move safely with clear examples and common mistakes.

cppc++11move-semanticsc++-faq

What T&& Means in C++11: Rvalue References Explained

Learn what T&& means in C++11, how rvalue references work, and why they matter for move semantics and perfect forwarding.

cppc++11rvalue-referencec++-faq

What `const` Means at the End of a Member Function in C++

Learn what `const` after a C++ member function means, how it affects `this`, and when to use const member functions safely.

cppdeclarationmember-functionsc++-faq

What the explicit Keyword Means in C++

Learn what the explicit keyword means in C++, how it affects constructors and conversions, and how to prevent unwanted implicit conversions.

cppconstructorexplicitc++-faq

When to Use Virtual Destructors in C++

Learn when and why to use virtual destructors in C++, with examples of polymorphism, base pointers, object cleanup, and common mistakes.

cpppolymorphismshared-ptrvirtual-destructor

When to Use static_cast, dynamic_cast, const_cast, and reinterpret_cast in C++

Learn when to use C++ casts safely: static_cast, dynamic_cast, const_cast, reinterpret_cast, and C-style casts with examples.

cpppointerscastingc++-faq

Why "using namespace std;" Is Discouraged in C++

Learn why `using namespace std;` is often discouraged in C++, what problems it can cause, and when explicit `std::` is safer.

cppnamespacesstdusing-directives

Why C++ Can Run Faster Than Hand-Written Assembly in Collatz Code

Learn why optimized C++ can beat naive assembly by understanding compiler optimizations, costly instructions, and CPU performance basics.

cppperformanceassemblyoptimization

Why C++ Programmers Should Minimize Use of new

Learn why C++ code should prefer stack objects, RAII, and smart pointers over raw new, and how value semantics improve safety.

cppmemory-managementheap-memorynew-operator

Why C++ Templates Are Usually Implemented in Header Files

Learn why C++ templates are usually defined in header files, how instantiation works, and what alternatives exist in real projects.

cpptemplatesundefined-referencec++-faq

Why C++ stdin Line Reading Can Be Slower Than Python: cin, sync_with_stdio, and fgets

Learn why C++ line input from stdin can be slower than Python and how sync_with_stdio(false) or fgets improves performance.

cpppythonbenchmarkingiostream

Why Separate Loops Can Be Faster Than a Combined Loop in C++: Cache, Memory Bandwidth, and Loop Optimization

Learn why splitting array updates into separate C++ loops can outperform a combined loop due to cache behavior, bandwidth, and compiler effects.

cppperformancex86vectorization

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.

cppperformanceassemblyx86

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.

cppjavaperformancecpu-architecture

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.

cppswitch-statement

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.

cpppolymorphismvirtual-functions

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.

cppperformancevisual-studio-2010compilation

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.

cppc++11constantsconstexpr

Page 3 of 4 - 62 questions