<table class="provenance-header" style="border: 0; border-collapse: collapse; margin: 0 0 16px 0; width: 100%;">
<tr style="border: 0;">
<td style="border: 0; vertical-align: top; padding: 0 24px 0 0;">

> **Source:** [https://foxhop.net/f3aadc3e-2f95-11f1-98f8-e86a64d24d78/cpp-pointers](https://foxhop.net/f3aadc3e-2f95-11f1-98f8-e86a64d24d78/cpp-pointers)  
> **Snapshot:** 2026-10-16T09:14:59Z  
> **Generator:** Remarkbox `d747782`  
>
> *This is a thread snapshot. The living document lives at the source URI above — it may have been edited, extended, or replied-to since.*

</td>
<td style="border: 0; vertical-align: top; width: 200px; text-align: right;">

![Scan for living source](data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKQAAACkAQAAAAAxzrjsAAABbElEQVR42tWXMbLcMAxDObkA739L3IDBg1yk+E1mUCTyeiW5oLEgCHHnfhiaf/jpzOzpdndGfM3q1/w0/ubp3J4/zH7xt+3EHYM8IxVIs+3FJeh8sItxDdjRSMH24h6hj+gHDy1+IeCPUdMDY2WYhow0UF+H32QtIlN2nbgjGaGMmMVQKiW8Ny9pC+Z10bX0IF+eDTmbkh5QmUMi3ucQJbwQm9w9krkqOlOiO2loQllX8DpPRuyf/3K4avEbIYQC8zs9fkXFAVbRWonfjQzEjTuY7q3VG9VATcBH7bzQcwdhlp+aKzojsHDze/5Q8rOJMyRnGy23dIYtCC+75LClX31KI2+8YqfFg7EqJwYL6Xr+u8nfm67lv1+HtWmqksAS3icClAbiLZ7HcYnBgePvtf4BMaAMvR6i1u9YaGGD0pgr92fxX2JfsZ+k7KBC6dJqcbFKCgIza/brOeNY55Tr9ZOKCXPSX1O//8//rN8VI860PEbqLQAAAABJRU5ErkJggg==)

</td>
</tr>
</table>

# cpp Pointers

**if p is a pointer**

&p

:   the memory address of p

\*p

:   the content that p points to

p

:   the content of p (or the address that p points to)

## Dynamic memory allocation or alias

**Useful but dangerous\...**

::: {#cb1}
    int *p, *q; // create two pointers, named p and q

    p = new int; // 

    *p = 100;

    q = p;

    *q = 200;

    q = new int;

    *q = *p;

    delete p; // give memory that p occupied back to operating system

    p = NULL; // set p to memory address 0  

    delete q; // give memory that q occupied back to operating system

    q = NULL; // set q to memory address 0
:::

## Dynamic Allocation for arrays

::: {#cb2}
    int size = 5;         // create an integer
    int *A;               // create an array of pointers

    A = new int[ size ];  // Ask for a certain size for your array

    A[0] = 10;            // Give values to Array
    A[1] = 20;
    A[2] = 30;
    A[3] = 40; 
    A[4] = 50; 

    //       8    32   32       36       40
    cout << &A << A << A + 0 << A + 1 << A + 2

    //       10      28      30
    cout << A[0] << A[1] << A[2] 

    //       10      10       28        30
    cout << *A << *A + 0 << A + 1 << * A + 2

    delete []A;
    A = NULL;
:::


---

**Source:** [https://foxhop.net/f3aadc3e-2f95-11f1-98f8-e86a64d24d78/cpp-pointers](https://foxhop.net/f3aadc3e-2f95-11f1-98f8-e86a64d24d78/cpp-pointers)  
**Snapshot:** 2026-10-16T09:14:59Z  
**Generator:** Remarkbox `d747782`
