What is a Pointer?

A pointer is a variable that stores the memory address of another variable.

Pointer Declaration and Initialization

int a = 5;
int* ptr = &a;  // ptr stores the address of 'a'

Visual Representation:

Variable 'a':                    Pointer 'ptr':
┌─────────────┐                 ┌─────────────────┐
│ Name: a     │                 │ Name: ptr       │
│ Value: 5    │                 │ Value: 0x...6ac │ ──┐
│ Addr: 0x6ac │ ←───────────────│ Addr: 0x...6a8  │   │
└─────────────┘                 └─────────────────┘   │
                                                      │
Memory Layout:                                        │
┌─────────────────────────────────────────────────────┴──┐
│ 0x...6a8 │  0x...6ac  │ 0x...6ac │    5    │           │
│   ptr    │   (value)  │    a     │ (value) │           │
└────────────────────────────────────────────────────────┘

Key Pointer Operators

Operator Name Purpose Example
& Address-of Gets memory address &a
* Dereference Gets value at address *ptr

Understanding Memory and Symbol Table

What is a Symbol Table?

A symbol table is a data structure used by the compiler to store information about variables, functions, and other identifiers in your program.

Symbol Table Structure:

| Variable Name | Data Type | Memory Address | Value |
|---------------|-----------|----------------|-------|
| a             | int       | 0x7fff5fbff6ac | 5     |
| b             | int       | 0x7fff5fbff6a8 | 10    |
| c             | char      | 0x7fff5fbff6a7 | 'A'   |

How Normal Variables Work

Step 1: Variable Declaration

int a = 5;

Step 2: Memory Allocation Process

Variable 'a' → Symbol Table Entry → Memory Address Assignment
                                  ↓
                              Stack Memory
                          [0x7fff5fbff6ac: 5]

Visual Representation:

Symbol Table:
┌─────────────────────┐
│ Name: a             │
│ Type: int           │
│ Address: 0x...f6ac  │ ──────┐
│ Value: 5            │       │
└─────────────────────┘       │
                              │
                              ▼
                        Memory (Stack):
                    ┌─────────────────────┐
                    │ 0x...f6ac │    5    │
                    └─────────────────────┘