Presentation is loading. Please wait.

Presentation is loading. Please wait.

Pointers & Objects.

Similar presentations


Presentation on theme: "Pointers & Objects."— Presentation transcript:

1 Pointers & Objects

2 Objects on Stack Objects created without new are on the stack: 2000 p1
Address Identifier Value 2000 p1 Point 1996 1992 1988 1984 1980 1976 1000 999 998 997 996 995

3 Objects on Heap Objects created with new are on heap
Use pointer to keep track of Address Identifier Value 2000 pp 1000 1996 1992 1988 1984 1980 1976 Point 999 998 997 996 995

4 Objects on Heap Objects can be on the heap:
But member access is tricky

5 Pointer Member Access Precedence : * comes after .
*pp.getX() == *(pp.getX()) Ask memory address to getX??? Address Identifier Value 2000 pp 1000 1996 1992 1988 1984 1980 1976 Point 999 998 997 996 995

6 Pointer Member Access Precedence corrected with ( )
Go to point pp points to, ask it to getX() Address Identifier Value 2000 pp 1000 1996 1992 1988 1984 1980 1976 Point 999 998 997 996 995

7 Pointer Member Access (*pointer).member Gets ugly

8 Pointer Member Access (*pointer).member -> : pointer member access
Gets ugly -> : pointer member access Dereference pointer, access member in one

9 Pointer Member Access -> : pointer member access Much better for:
Dereference pointer, access member in one Much better for:


Download ppt "Pointers & Objects."

Similar presentations


Ads by Google