`int` — C++ Keyword

`int` — C++ Keyword

The int keyword in C++: the natural signed integer type for the platform.

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.

int

The natural signed integer type for the platform, guaranteed to be at least 16 bits but typically 32 bits on all modern architectures.

Syntax

int n;
int n = 42;
unsigned int u = 42u;
long int l;   // int suffix is optional

Example

#include <print>
#include <climits>

int main() {
    int a = 10, b = 3;

    std::println("{}", a + b);   // 13
    std::println("{}", a / b);   // 3  (truncated integer division)
    std::println("{}", a % b);   // 1  (remainder)

    std::println("min: {} max: {}", INT_MIN, INT_MAX);
    // min: -2147483648 max: 2147483647 (on 32-bit int platforms)

    // Overflow is undefined behavior for signed int
    // int overflow = INT_MAX + 1;   // UB!
}

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;
}