Questions

C++ questions

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

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 extern in C++: Declarations and Definitions

Learn when to use extern in C++ to declare variables defined in another source file, prevent duplicate definitions, and share global state safely.

cppvariable-declaration

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++ Compilation Can Take Longer Than C# and Java

Learn why C++ builds can be slow, including headers, templates, preprocessing, optimization, linking, and practical ways to speed them up.

cppperformancecompilation

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++ Uses Header Files and .cpp Files

Learn why C++ separates declarations in header files from definitions in .cpp files, including compilation, linking, include guards, and project structure.

cppheader-files

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 GCC -Os Can Beat -O2: Code Alignment and CPU Front-End Effects

Learn why GCC -Os can occasionally beat -O2: instruction alignment, CPU front-end effects, reliable benchmarks, and investigation techniques.

cppperformancegccx86-64

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

Page 7 of 8 - 158 questions