4 - Pointers
4 - Pointers
COMP315
2024
1
2
Pointers
• A pointer is the memory address of a variable. The address “points”
to the variable because it identifies the variable by stating where the
variable is, rather than stating what the variable’s name is
Pointers be like…
3
Operators
• Referencing operator (&): The operator in front of an ordinary
variable produces the address of that variable. It produces a pointer
that points to the variable
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Code Example
int v = 48;
int *p = &v;
int &r = v;
20
Code Example – with Table
Variable Name Value Memory Address
int v = 48; v 48 ox3afee2
int *p = &v; r 48 ox3afee2
int &r = v; p ox3afee2 ox3afee3
21
Code Example
int v = 48;
int *p = &v;
int &r = v;
*p = 12;
y=10;