Download presentation
Presentation is loading. Please wait.
1
1 Pointers Revisited Linda M c Iver
2
2 Pointer Examples int i = 0; 0x2000 0x2001 0x2002 0x2003
3
3 Pointer Examples 0 int i = 0; i 0x2000 0x2001 0x2002 0x2003
4
4 Pointer Examples 0 int i = 0; int* intPtr = NULL; i 0x2000 0x2001 0x2002 0x2003 int i = 0;
5
5 Pointer Examples 0NULL int i = 0; int* intPtr = NULL; i intPtr 0x2000 0x2001 0x2002 0x2003 int i = 0;
6
6 Pointer Examples 0 NULL int i = 0; int* intPtr = NULL; intPtr = &i; i intPtr 0x2000 0x2001 0x2002 0x2003
7
7 Pointer Examples 0 0x2000 int i = 0; int* intPtr = NULL; intPtr = &i; i intPtr 0x2000 0x2001 0x2002 0x2003
8
8 Pointer Examples 0 0x2000 i intPtr 0x2000 0x2001 0x2002 0x2003 What do these expressions evaluate to? &i intPtr *intPtr i &intPtr
9
9 Pointer Examples 0 0x2000 i intPtr 0x2000 0x2001 0x2002 0x2003 What do these expressions evaluate to? &i 0x2000 intPtr *intPtr i &intPtr
10
10 Pointer Examples 0 0x2000 i intPtr 0x2000 0x2001 0x2002 0x2003 What do these expressions evaluate to? &i 0x2000 intPtr0x2000 *intPtr i &intPtr
11
11 Pointer Examples 0 0x2000 i intPtr 0x2000 0x2001 0x2002 0x2003 What do these expressions evaluate to? &i 0x2000 intPtr0x2000 *intPtr0 i &intPtr
12
12 Pointer Examples 0 0x2000 i intPtr 0x2000 0x2001 0x2002 0x2003 What do these expressions evaluate to? &i 0x2000 intPtr0x2000 *intPtr0 i0 &intPtr
13
13 Pointer Examples 0 0x2000 i intPtr 0x2000 0x2001 0x2002 0x2003 What do these expressions evaluate to? &i 0x2000 intPtr0x2000 *intPtr0 i0 &intPtr0x2001
14
14 Pointer Examples &i == intPtr == 0x2000 i == *intPtr == 0 int i = 0; int* intPtr = NULL; intPtr = &i; 0 0x2000 i intPtr 0x2000 0x2001 0x2002 0x2003
15
15 Pointer Examples 'b' char c = 'b'; c 0x2000 0x2001 0x2002 0x2003
16
16 Pointer Examples 'b'NULL char c = 'b'; char* charPtr = NULL; c charPtr 0x2000 0x2001 0x2002 0x2003
17
17 Pointer Examples 'b'NULL char c = 'b'; char* charPtr = NULL; c charPtr 0x2000 0x2001 0x2002 0x2003 What does *charPtr evaluate to now?
18
18 Pointer Examples 'b'NULL 'L' char c = 'b'; char* charPtr = NULL; char initial = 'L'; c charPtr initial 0x2000 0x2001 0x2002 0x2003
19
19 Pointer Examples 'b'0x2000 'L' char c = 'b'; char* charPtr = NULL; char initial = 'L'; charPtr = &c; c charPtr initial 0x2000 0x2001 0x2002 0x2003
20
20 Pointer Examples 'b'0x2000 'L' char c = 'b'; char* charPtr = NULL; char initial = 'L'; charPtr = &c; c charPtr initial 0x2000 0x2001 0x2002 0x2003 What does *charPtr evaluate to now?
21
21 Pointer Examples 'b'0x2002 'L' char c = 'b'; char* charPtr = NULL; char initial = 'L'; charPtr = &c; charPtr = &initial; c charPtr initial 0x2000 0x2001 0x2002 0x2003
22
22 Pointer Examples 'b'0x2002 'L' char c = 'b'; char* charPtr = NULL; char initial = 'L'; charPtr = &c; charPtr = &initial; c charPtr initial 0x2000 0x2001 0x2002 0x2003 What does *charPtr evaluate to now?
23
23 Pointer Summary A pointer holds an address & gives you the address of a variable *somePtr is a de-reference, which gives you the value of the variable pointed to by somePtr Like variables, pointers have a particular type
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.