> ## 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++ Pointer Parameter

A pointer parameter in C++ is a function parameter declared to accept a memory address rather than a direct value or a reference. When a function is invoked with a pointer argument, the memory address is passed by value. This means the function receives a local copy of the pointer, but this copied pointer still holds the address of the original object in the caller's scope, allowing indirect manipulation of that object.

## Syntax and Dereferencing

To declare a pointer parameter, the type is followed by an asterisk (`*`). To access or mutate the underlying data within the function, you must use the indirection operator (`*`) or the member access operator (`->` for objects). The caller must provide an address, typically using the address-of operator (`&`).

```cpp theme={"dark"}
void mutateData(int* ptr) {
    if (ptr != nullptr) {
        *ptr = 42; // Dereferencing the pointer to mutate the original memory
    }
}

int main() {
    int value = 10;
    mutateData(&value); // Passing the memory address of 'value'
    return 0;
}
```

## Technical Characteristics

* **Pass-by-Value Semantics:** Because the pointer itself is passed by value, reassigning the pointer parameter inside the function only modifies the local copy. It does not change the memory address held by the caller's pointer.
* **Nullability:** Unlike C++ references, pointer parameters are inherently nullable. They can accept `nullptr`, which requires explicit null-checking within the function body to prevent undefined behavior from dereferencing a null address.
* **Pointer Arithmetic:** If the pointer parameter points to an element within a contiguous memory block (like an array), pointer arithmetic (`ptr++`, `ptr + 2`) can be applied to traverse the memory.

## Const Correctness

Pointer parameters interact with the `const` qualifier in three distinct ways, depending on whether the data, the pointer itself, or both are immutable.

```cpp theme={"dark"}
// 1. Pointer to constant data
// The function cannot modify the underlying integer, but can reassign 'ptr' locally.
void readOnlyData(const int* ptr); 

// 2. Constant pointer to mutable data
// The function can modify the underlying integer, but cannot reassign 'ptr' to a new address.
void readOnlyPointer(int* const ptr); 

// 3. Constant pointer to constant data
// The function can neither modify the underlying integer nor reassign 'ptr'.
void strictlyReadOnly(const int* const ptr); 
```

## Modifying the Caller's Pointer

Because standard pointer parameters pass the address by value, a function cannot allocate new memory and assign it to the caller's original pointer using a single `*`. To modify the caller's actual pointer (changing the address it holds), you must use a pointer-to-pointer (`**`) or a reference-to-a-pointer (`*&`).

```cpp theme={"dark"}
// Using a pointer-to-pointer
void reallocatePointer(int** doublePtr) {
    *doublePtr = new int(100); // Modifies the caller's pointer address
}

// Using a reference-to-a-pointer (Idiomatic C++)
void reallocatePointerRef(int*& ptrRef) {
    ptrRef = new int(100);     // Modifies the caller's pointer address directly
}
```

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