> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# C++ int

The `int` keyword in C++ designates a fundamental, built-in numeric data type used to represent signed, exact-value integers. By default, `int` is a signed type. As of C++20, the standard mandates that signed integers use Two's Complement representation, where the most significant bit acts as a sign bit with a negative weight, and the remaining bits contribute to the overall value.

## Memory Allocation and Data Models

The C++ standard does not prescribe a fixed size in bytes for `int`. Instead, it dictates minimum width requirements based on the underlying architecture's data model.

* **Standard Guarantee:** The standard guarantees that an `int` will be at least 16 bits wide. Note that this does not strictly equate to 2 bytes; the standard defines size in terms of `char` (bytes), and the number of bits in a byte (`CHAR_BIT`) is only guaranteed to be *at least* 8.
* **Modern Architectures:** In nearly all modern 32-bit and 64-bit data models (such as ILP32, LP64, and LLP64), `int` is implemented as a 32-bit integer.

## Syntax and Initialization

C++ supports multiple initialization paradigms for `int`. Uniform (brace) initialization is the modern standard as it strictly prohibits narrowing conversions.

```cpp theme={"dark"}
// Declaration without initialization.
// Contains an indeterminate garbage value if it has automatic storage duration (local block-scope).
// Zero-initialized if it has static or thread storage duration (namespace/global scope).
int uninitialized_val;

// Copy initialization
int copy_val = 42;

// Direct initialization
int direct_val(42);

// Uniform / Brace initialization (C++11 onwards)
int brace_val{42}; 

// Zero-initialization via empty braces
int zero_val{}; 
```

## Value Range and Representation

Because C++20 requires **Two's Complement** representation, the range of an `int` is strictly determined by its bit width ($n$), calculated as $-2^{n-1}$ to $2^{n-1} - 1$.

Assuming the standard modern 32-bit implementation:

* **Minimum Value:** `-2,147,483,648`
* **Maximum Value:** `2,147,483,647`

These limits can be queried programmatically at compile-time using the `<limits>` header:

```cpp theme={"dark"}
#include <limits>

constexpr int min_val = std::numeric_limits<int>::min();
constexpr int max_val = std::numeric_limits<int>::max();
```

## Type Modifiers

The `int` type serves as the base for several modified integer types, which alter either the sign representation or the memory allocation:

* **Sign Modifiers:**
  * `signed int` (Identical to `int`)
  * `unsigned int` (Uses all bits for magnitude, shifting the 32-bit range to `0` through `4,294,967,295`)
* **Size Modifiers:**
  * `short int` (Guaranteed minimum 16 bits)
  * `long int` (Guaranteed minimum 32 bits)
  * `long long int` (Guaranteed minimum 64 bits)

*Note: When using modifiers, the `int` keyword itself can be omitted (e.g., `unsigned` is synonymous with `unsigned int`).*

## Overflow Behavior

According to the C++ standard, **signed integer overflow invokes undefined behavior (UB)**. If an operation causes an `int` to exceed its maximum or minimum representable value, the compiler is permitted to optimize out the check or execute unpredictable instructions. This contrasts with `unsigned int`, which is guaranteed to wrap around modulo $2^n$.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor C++ Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
