Skip to main content
CodeSpeedTest
Languages
Start TypingJump into a test — pick any languageAdaptive TrainingUnlock chars as you master them — home row to !@#$%Practice DrillsFocused sessions targeting weak spotsDaily ChallengesNew coding challenges every dayRace ModeCompete against others in real timeAI OpponentRace against an AI at your WPM level
LeaderboardGlobal rankings for every languageCertificatesEarn verifiable Bronze / Silver / Gold certsActivityDaily streaks & historical analyticsProfileYour stats, badges & achievements
Browse Languages500+ languages with real code examplesBlogTips, guides & deep divesFAQCommon questions answeredGetting StartedNew to CodeSpeedTest?AboutOur story & mission
Pricing
Start Typing
Tools/C++ Syntax

C++ Syntax Drill

Modern C++ keywords, STL containers, and essential patterns — smart pointers, templates, lambdas, and range-based loops — in one compact reference.

C++ Keywords

KeywordDescription
autoDeduce type from initializer (C++11)
constImmutable variable or member (cannot be changed)
constexprEvaluate expression at compile time (C++11)
constevalMust be evaluated at compile time (C++20)
nullptrNull pointer constant (replaces NULL)
classDefine a class (default private)
structDefine a struct (default public)
templateGeneric type or function parameter
typenameIntroduce a type parameter in templates
namespaceGroup names to avoid collisions
usingBring name into scope / type alias
virtualEnable polymorphic dispatch (override in subclass)
overrideExplicitly mark a virtual method override (C++11)
finalPrevent further inheritance or overriding (C++11)
explicitPrevent implicit conversions for constructors
publicMember accessible everywhere
privateMember accessible only within the class
protectedAccessible in class and derived classes
staticShared across all instances; or local persistent storage
inlineHint to expand function at call site
noexceptDeclare a function won't throw (C++11)
deleteDisable a function / free heap memory
newAllocate on the heap
operatorDefine or override an operator
mutableAllow modification in const context
friendGrant external access to private members
typedefCreate a type alias (older style)
enum classStrongly typed enumeration (C++11)
static_assertCompile-time assertion
decltypeQuery the type of an expression

STL Containers

Choosing the right container is one of the most important performance decisions in C++.

ContainerDescription
std::vector<T>Dynamic array — O(1) amortised push_back, random access
std::array<T, N>Fixed-size stack array with STL interface
std::list<T>Doubly linked list — O(1) insert/erase at position
std::deque<T>Double-ended queue — fast front and back push
std::map<K, V>Sorted key-value store (red-black tree) — O(log n)
std::unordered_map<K, V>Hash map — O(1) average lookup
std::set<T>Sorted unique elements — O(log n)
std::unordered_set<T>Hash set — O(1) average lookup
std::multimap<K, V>Sorted map allowing duplicate keys
std::priority_queue<T>Max-heap by default — O(log n) push/pop
std::queue<T>FIFO adapter over deque
std::stack<T>LIFO adapter over deque
std::pair<A, B>Simple two-element tuple
std::tuple<Ts...>Heterogeneous fixed-size collection
std::optional<T>Value that may or may not be present (C++17)
std::variant<Ts...>Type-safe union (C++17)
std::stringDynamic character sequence
std::string_viewNon-owning view of a string (C++17)

Common Patterns

Hello World & Basics

#include <iostream>
#include <string>

int main() {
    std::string name = "World";
    std::cout << "Hello, " << name << "!\n";
    return 0;
}

Range-Based For & Lambda

#include <vector>
#include <algorithm>
#include <iostream>

int main() {
    std::vector<int> numbers = {5, 3, 8, 1, 9, 2};

    // Range-based for loop
    for (const auto& n : numbers) {
        std::cout << n << " ";
    }

    // Sort with lambda
    std::sort(numbers.begin(), numbers.end(),
        [](int a, int b) { return a < b; });

    // Lambda with capture
    int threshold = 5;
    auto isAbove = [threshold](int n) { return n > threshold; };
    auto count = std::count_if(numbers.begin(), numbers.end(), isAbove);
    std::cout << "\nAbove threshold: " << count << "\n";
}

Smart Pointers

#include <memory>
#include <iostream>

struct Node {
    int value;
    std::unique_ptr<Node> next;

    explicit Node(int val) : value(val) {}
};

int main() {
    // unique_ptr — sole ownership, auto-deleted
    auto head = std::make_unique<Node>(1);
    head->next = std::make_unique<Node>(2);

    // shared_ptr — reference counted ownership
    auto shared = std::make_shared<Node>(42);
    auto also = shared; // ref count = 2

    // weak_ptr — non-owning observer
    std::weak_ptr<Node> observer = shared;
    if (auto locked = observer.lock()) {
        std::cout << locked->value << "\n";
    }
}

Template Function

#include <iostream>
#include <vector>

template<typename T>
T findMax(const std::vector<T>& items) {
    if (items.empty()) throw std::runtime_error("Empty container");
    T maxVal = items[0];
    for (const auto& item : items) {
        if (item > maxVal) maxVal = item;
    }
    return maxVal;
}

int main() {
    std::vector<int> ints = {3, 7, 2, 9, 1};
    std::cout << findMax(ints) << "\n"; // 9

    std::vector<double> dbls = {1.5, 2.7, 0.3};
    std::cout << findMax(dbls) << "\n"; // 2.7
}

Practice typing these in CodeSpeedTest →

C++ has some of the most symbol-heavy syntax of any language. Getting fluent with angle brackets, scope resolution, and pointer syntax requires deliberate practice.

Start typing C++ →Browse all languages
CodeSpeedTest

Improve your coding speed, code accuracy, and programming syntax WPM with practice sessions across 500+ programming languages.

Quick Links

HomeAboutFeaturesGetting StartedLanguages

Resources

Pro ⚡ PricingCertifyFAQBlogContactLeaderboardRaceChallengesFree ToolsWPM CalculatorPrivacy PolicyTerms of Service

Connect

CodeSpeedTest on GitHubCodeSpeedTest on TwitterEmail CodeSpeedTest

© 2026 CodeSpeedTest. All rights reserved.