Questions

C++ questions

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

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 `int argc, char *argv[]` Means in C++ main()

Learn what `argc` and `argv` mean in C++ main(), how command-line arguments work, and when you should use them in real programs.

cppparameterscommand-line-argumentsargv

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 Forward Declarations in C++

Learn when forward declarations are valid in C++, when you need full class definitions, and how they affect headers, inheritance, members, and references.

cppforward-declarationc++-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 inline for Functions in C++

Learn what C++ inline really means, when to use it, when not to, and how compilers decide whether to inline a function.

cppinlineone-definition-ruleinline-functions

When to Use malloc vs new in C++

Learn when to use malloc/free and new/delete in C++, why they differ, when to avoid both, and the safest modern C++ approach.

cppmemory-managementmallocnew-operator

When to Use noexcept in C++: Practical Rules, Performance, and Best Practices

Learn when to use noexcept in C++, how it affects move operations, containers, optimization, and which functions should be marked safely.

cppc++11exceptionnoexcept

When to Use reinterpret_cast vs static_cast in C++

Learn when to use reinterpret_cast and static_cast in C++, especially for void* and C/C++ interop, with examples and common pitfalls.

cppcastingreinterpret-cast

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 Looping Over 8192 Elements Is Slow in C: Cache Effects, Stride Access, and Memory Layout

Learn why a C program slows down at size 8192 due to cache conflicts, row-major layout, and memory access patterns, plus how to fix it.

cppperformancememory-managementgcc

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 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.

cppcastingstatic-cast

Page 5 of 6 - 110 questions