`register` — C++ Keyword

`register` — C++ Keyword

The register keyword in C++: deprecated storage class specifier, ignored by modern compilers.

How to use this reference page

Use reference pages to confirm names, categories, nearby facilities, and the constraints that matter before writing or reviewing code.

  • Scan the top of the page first to identify the primary types, functions, or algorithm families involved.
  • Use the nearby-page links when your question is really about a companion header, related algorithm family, or broader subsystem.
  • Validate tricky behavior with a small compileable example before relying on memory for details like invalidation, ordering, allocation, or lifetime rules.

register

A historic storage class hint asking the compiler to keep the variable in a CPU register for fast access. Since C++17 the keyword is deprecated; compilers ignore it and modern optimizers automatically allocate hot variables to registers.

Syntax

register Type name;    // valid but deprecated in C++17; removed meaning from C++17 onward

Example

// Historical usage - avoid in new code
int sum_array(const int* arr, int n) {
    register int sum = 0;   // deprecated hint
    for (int i = 0; i < n; ++i) {
        sum += arr[i];
    }
    return sum;
}

Notes

Example in practice

int main() {
    // Pick one facility from this reference page.
    // Write the smallest program that exercises its main precondition,
    // complexity rule, or lifetime constraint before scaling up.
    return 0;
}