Copyright 1996 by Addison-Wesley Publishing Company 1
Chapter 1
Pointers, Arrays, and Structures
Copyright
1996 by Addison-Wesley Publishing Company 2
Pointer illustration
X = 5
Y = 7
1000
(&X) 1000
(&Y) 1004
(&Ptr) 1200
5
Ptr X
Copyright
1996 by Addison-Wesley Publishing Company 3
Result of
*Ptr=10
X = 10
Y = 7
Ptr = &X = 1000
(&X) 1000
(&Y) 1004
(&Ptr) 1200
10
Ptr X
Copyright
1996 by Addison-Wesley Publishing Company 4
Uninitialized pointer
X = 5
Y = 7
Ptr = ?
(&X) 1000
(&Y) 1004
(&Ptr) 1200
5
Ptr X
Copyright
1996 by Addison-Wesley Publishing Company 5
(a) Initial state; (b)
Ptr1=Ptr2
starting from initial state;
(c)
*Ptr1=*Ptr2
starting from initial state
Ptr1 X Ptr1 X Ptr1
Ptr2 Y Ptr2 Y Ptr2
5
7
5
7
(a) (b)