C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.
-
Upload
madison-cobb -
Category
Documents
-
view
222 -
download
1
Transcript of C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.
![Page 1: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/1.jpg)
CHAPTER 03
PointersCompiled by Dr. Mohammad Alhawarat
![Page 2: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/2.jpg)
2
WHAT SIZE SHOULD WE MAKE THE CHECKS ARRAY? If it is too small, it might get filled up. If it is too large, many clients will only use
a small fraction of the array space, and we will be wasting memory.
The best approach might be to start an array off as small, then have it grow larger as more checks are written.
This cannot be done with ordinary arrays, but it can be done with pointers and dynamically-allocated memory.
![Page 3: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/3.jpg)
3
MEMORY TERMINOLOGY
variable name variable value address – a binary number used by the
operating system to identify a memory cell of RAM
It is important to know the precise meanings of these terms
![Page 4: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/4.jpg)
4
MEMORY TERMINOLOGY(CONT.)
Addresses
00110
01010
01110
10010
10110
x15
![Page 5: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/5.jpg)
5
MEMORY TERMINOLOGY(CONT.)
Addresses
00110
01010
01110
10010
10110
x15
Variable name
![Page 6: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/6.jpg)
6
MEMORY TERMINOLOGY(CONT.)
Addresses
00110
01010
01110
10010
10110
x15
A variable (which is a location)
![Page 7: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/7.jpg)
7
MEMORY TERMINOLOGY(CONT.)
Addresses
00110
01010
01110
10010
10110
x15
Value of the variable
![Page 8: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/8.jpg)
8
MEMORY TERMINOLOGY(CONT.)
Addresses
00110
01010
01110
10010
10110
x15
Address of the variable
![Page 9: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/9.jpg)
9
POINTERS
A pointer is a variable used to store an address
The declaration of a pointer must have a data type for the address the pointer will hold (looks like this):
int *ptr; char *chptr;
![Page 10: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/10.jpg)
10
LOCATION BEHAVIOR
A variable is a location When locations are used in code, they
behave differently depending on whether or not they are used on the left side of an assignment
If not used on the left side of an assignment, the value at the location is used
When used on the left side of assignment, the location itself is used
![Page 11: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/11.jpg)
11
ADDRESS-OF OPERATOR
An address can be assigned to a pointer using the address-of operator &:
int *ptr;int x;ptr = &x;
![Page 12: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/12.jpg)
12
RESULT
xptr
Addresses
00110
01010
01110
10010
10110
x
ptr01010
![Page 13: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/13.jpg)
13
DEREFERENCE OPERATOR The dereference operator, *, is used on a
pointer (or any expression that yields an address)
The result of the dereference operation is a location (the location at the address that the pointer stores)
Therefore, the way the dereference operator behaves depends on where it appears in code (like variables)
![Page 14: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/14.jpg)
14
INT X = 3, *PTR;
ptrx3
![Page 15: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/15.jpg)
15
PTR = &X; (WHAT HAPPENS?)
ptrx3
![Page 16: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/16.jpg)
16
PTR = &X;
ptrx3
![Page 17: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/17.jpg)
17
Y = *PTR + 5; (WHAT HAPPENS?)
ptrx3
y
![Page 18: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/18.jpg)
18
Y = *PTR + 5;
ptrx3
y8
![Page 19: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/19.jpg)
19
INT Z = 5;
ptrx3
y8
z5
![Page 20: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/20.jpg)
20
*PTR = 10 + Z; (WHAT HAPPENS?)
ptrx
y8
z5
3
![Page 21: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/21.jpg)
21
*PTR = 10 + Z;
ptrx
y8
z5
15
![Page 22: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/22.jpg)
22
*PTR = 10 + Z;
ptrx
y8
z5
15
Note that the value of x changes even though this line of code doesn’t contain x
![Page 23: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/23.jpg)
23
ARRAYS
The address of an array is the same as the address of the first element of the array.
An array’s name (without using an index) contains the address of the array.
The address of the array can be assigned to a pointer by assigning the array’s name to the pointer.
An array name is not a pointer because the address in it cannot be changed (the address in a pointer can be changed).
![Page 24: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/24.jpg)
24
THE [ ] OPERATOR When an array is indexed, [ ] is an
operator. For example, nums[3] produces the
result *( nums + 3 ). C++ produces an address from the
expression nums + 3, by:Noting what data type is stored at the
address that nums containsMultiplying 3 by the number of bytes in that
data typeAdding the product onto the address stored
in nums After the address is produced from nums
+ 3, it is dereferenced to get a location.
![Page 25: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/25.jpg)
25
THE HEAP
The heap is a special part of RAM memory reserved for program usage.
When a program uses memory from the heap, the used heap memory is called dynamically-allocated memory.
The only way to dynamically allocate memory (use memory in the heap) is by using the new operator.
![Page 26: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/26.jpg)
26
THE NEW OPERATOR The new operator has only one operand, which is
a data type. The new operation produces the address of an
unused chunk of heap memory large enough to hold the data type (dynamically allocated)
In order to be useful, the address must be assigned to a pointer, so that the dynamically allocated memory can be accessed through the pointer:
int *ptr;ptr = new int;*ptr = 5;
![Page 27: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/27.jpg)
27
INT *PTR;
ptr
![Page 28: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/28.jpg)
28
PTR = NEW INT;
ptr
![Page 29: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/29.jpg)
29
PTR = NEW INT;
ptr
![Page 30: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/30.jpg)
30
PTR = NEW INT;
ptrFound a block in heap
110110
![Page 31: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/31.jpg)
31
PTR = NEW INT;
ptr 110110
Replaces new operation
![Page 32: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/32.jpg)
32
PTR = 110110;
ptr 110110
![Page 33: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/33.jpg)
33
PTR = 110110;
ptr 110110
![Page 34: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/34.jpg)
34
*PTR = 5; (WHAT HAPPENS?)
ptr 110110
![Page 35: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/35.jpg)
35
*PTR = 5;
ptr 110110
5
![Page 36: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/36.jpg)
36
DYNAMICALLY-ALLOCATED MEMORY Has no name associated with it (other
locations have variable names associated with them)
Can only be accessed by using a pointer The compiler does not need to know the
size (in bytes) of the allocation at compile time
The compiler does need to know the size (in bytes) of any declared variables or arrays at compile time
![Page 37: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/37.jpg)
37
DYNAMIC ARRAYS The real advantage of using heap memory comes
from using arrays in heap memory Arrays can be allocated by the new operator; then
they are called dynamic arrays (but they have no name either)
int *ptr;ptr = new int [5]; // array of 5 integer elementsptr[3] = 10; // using the [ ] operator
![Page 38: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/38.jpg)
38
DYNAMIC ARRAYS (CONT.)
The size of a dynamic array does not need to be known at compile time:
int numElements;cout << “How many elements would you like?“;cin >> numElements;float *ptrArr = new float [ numElements ];
![Page 39: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/39.jpg)
39
WHAT HAPPENS AT THE END OF THIS FUNCTION?1 void foo( )2 {3 int numElements;4 cout << 5 “How many elements would you like the array to
have? “;6 cin >> numElements;7 float *ptrArr = new float [ numElements ];89 // the array is processed here10 // output to the user is provided here11 }
![Page 40: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/40.jpg)
40
MEMORY LEAK All local variables and the values they
contain are destroyed (numElements and ptrArr)
The address of the dynamic array is lost BUT…the dynamic array is not
destroyed The dynamic array can no longer be
used, but the new operator will consider it as used heap memory (and cannot reuse it for something else).
This is called memory leak. Memory leak is not permanent – it will
end when the program stops.
![Page 41: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/41.jpg)
41
MEMORY LEAK (CONT.)
Memory leak can easily be prevented during execution of a program.
A program that continually leaks memory may run out of heap memory to use.
Therefore, it is poor programming practice to allow memory leak to occur.
![Page 42: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/42.jpg)
42
THE DELETE OPERATOR1 void foo( )2 {3 int numElements;4 cout << 5 “How many elements would you like the array to
have? “;6 cin >> numElements;7 float *ptrArr = new float [ numElements ];89 // the array is processed here10 // output to the user is provided here1112 delete [ ] ptrArr; 13 }
Prevents memory leak – it frees the dynamic array so this memory can be reused by the new operator later on
![Page 43: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/43.jpg)
43
THE DELETE OPERATOR (CONT.) When the delete operator is being used to
free a variable pointed to by ptr:delete ptr;
When the delete operator is being used to free an array pointed to by ptr:delete [ ] ptr;
If you omit [ ] (common mistake), no compiler error will be given; however, only the first element of the array will be freed
![Page 44: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/44.jpg)
44
ANOTHER COMMON CAUSE OF MEMORY LEAK
First, pointer ptr is assigned the address of dynamically allocated memory.
ptr110110
5
![Page 45: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/45.jpg)
45
PTR = NEW INT; (WHAT HAPPENS?)
ptr110110
5
![Page 46: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/46.jpg)
46
PTR = NEW INT;
ptr110110
5
Unused block found in heap
111000
![Page 47: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/47.jpg)
47
PTR = 111000;
ptr110110
5
111000
![Page 48: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/48.jpg)
48
PTR = 111000;
ptr110110
5
111000
![Page 49: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/49.jpg)
49
PTR = 111000;
ptr110110
5
111000
The address of this block is not stored anywhere, but it hasn’t been freed – memory leak
![Page 50: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/50.jpg)
50
AVOIDING MEMORY LEAK
When you want to change the address stored in a pointer, always think about whether or not the current address is used for dynamically-allocated memory
If it is (and that memory is no longer useful), use the delete operator before changing the address in the pointer; for example,
delete ptr;
![Page 51: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/51.jpg)
51
POINTERS TO OBJECTS
Pointers can be used to point to objects or arrays of objects:
Check *chkptr = new Check;Check *chkarrptr = new Check [10];
The delete operator is used the same way:
delete chkptr;delete [ ] chkarrptr;
![Page 52: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/52.jpg)
52
RUNNING OUT OF HEAP MEMORY We can run out of heap memory if:
We write poor code that continually allows memory leak while constantly using the new operator
OR … If we use excessive amounts of heap
memory If the new operator cannot find a
chunk of unused heap memory large enough for the data type, the new operation throws an exception
![Page 53: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/53.jpg)
53
CODE FOR EXCEPTIONS1 int main( ) 2 {3 char *ptr;45 try {6 ptr = new char[ 1000000000 ];7 }89 catch( … ) {10 cout << "Too many elements" << endl;11 }1213 return 0;14 }
try clause
catch clause
![Page 54: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/54.jpg)
54
CODE FOR EXCEPTIONS (CONT.)1 int main( ) 2 {3 char *ptr;45 try {6 ptr = new char[ 1000000000 ];7 }89 catch( … ) {10 cout << "Too many elements" << endl;11 }1213 return 0;14 }
The program will crash if try/catch clauses are not written for code that ultimately causes an exception
![Page 55: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/55.jpg)
55
ANOTHER EXAMPLE
1 int main( )2 {3 Foo foo;5 try {6 foo.bar1( 35 );7 foo.bar2( 10 );8 foo.bar3( );9 }11 catch ( … ) {12 cout << "Out of memory" << endl;13 }15 return 0;16 }
These functions use the new operator.
![Page 56: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/56.jpg)
56
ANOTHER EXAMPLE (CONT.)
1 int main( )2 {3 Foo foo;5 try {6 foo.bar1( 35 );7 foo.bar2( 10 );8 foo.bar3( );9 }11 catch ( … ) {12 cout << "Out of memory" << endl;13 }15 return 0;16 }
The client usually writes the exception-handling code to do whatever they wish to do.
![Page 57: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/57.jpg)
57
ARRAY EXPANSION
5 7 4 2
ptr size is 4
A dynamic array is filled, and more data needs to be put in. Therefore, the array needs to be expanded.
![Page 58: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/58.jpg)
58
INT *TEMP = NEW INT [SIZE * 2];
5 7 4 2
ptr size is 4
![Page 59: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/59.jpg)
59
INT *TEMP = NEW INT [SIZE * 2];
5 7 4 2
ptr size is 4
temp
![Page 60: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/60.jpg)
60
FOR ( INT I = 0; I < SIZE; I++ ) TEMP[ I ] = PTR[ I ];
5 7 4 2
ptr size is 4
temp
![Page 61: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/61.jpg)
61
FOR ( INT I = 0; I < SIZE; I++ ) TEMP[ I ] = PTR[ I ];
5 7 4 2
ptr size is 4
temp
i is 0
![Page 62: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/62.jpg)
62
FOR ( INT I = 0; I < SIZE; I++ ) TEMP[ I ] = PTR[ I ];
5 7 4 2
ptr size is 4
temp
i is 0
5
![Page 63: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/63.jpg)
63
FOR ( INT I = 0; I < SIZE; I++ ) TEMP[ I ] = PTR[ I ];
5 7 4 2
ptr size is 4
temp
i is 1
5
![Page 64: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/64.jpg)
64
FOR ( INT I = 0; I < SIZE; I++ ) TEMP[ I ] = PTR[ I ];
5 7 4 2
ptr size is 4
temp
i is 1
5 7
![Page 65: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/65.jpg)
65
FOR ( INT I = 0; I < SIZE; I++ ) TEMP[ I ] = PTR[ I ];
5 7 4 2
ptr size is 4
temp
i is 2
5 7
![Page 66: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/66.jpg)
66
FOR ( INT I = 0; I < SIZE; I++ ) TEMP[ I ] = PTR[ I ];
5 7 4 2
ptr size is 4
temp
i is 2
5 7 4
![Page 67: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/67.jpg)
67
FOR ( INT I = 0; I < SIZE; I++ ) TEMP[ I ] = PTR[ I ];
5 7 4 2
ptr size is 4
temp
i is 3
5 7 4
![Page 68: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/68.jpg)
68
FOR ( INT I = 0; I < SIZE; I++ ) TEMP[ I ] = PTR[ I ];
5 7 4 2
ptr size is 4
temp
i is 3
5 7 4 2
![Page 69: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/69.jpg)
69
FOR ( INT I = 0; I < SIZE; I++ ) TEMP[ I ] = PTR[ I ];
5 7 4 2
ptr size is 4
temp
5 7 4 2
![Page 70: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/70.jpg)
70
DELETE [ ] PTR;
5 7 4 2
ptr size is 4
temp
5 7 4 2
![Page 71: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/71.jpg)
71
DELETE [ ] PTR;
ptr size is 4
temp
5 7 4 2
![Page 72: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/72.jpg)
72
PTR = TEMP;
ptr size is 4
temp
5 7 4 2
![Page 73: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/73.jpg)
73
PTR = TEMP;
ptr size is 4
temp
5 7 4 2
![Page 74: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/74.jpg)
74
SIZE = SIZE * 2;
ptr size is 4
temp
5 7 4 2
![Page 75: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/75.jpg)
75
SIZE = SIZE * 2;
ptr size is 8
temp
5 7 4 2
![Page 76: C HAPTER 03 Pointers Compiled by Dr. Mohammad Alhawarat.](https://reader034.fdocuments.net/reader034/viewer/2022042616/56649f335503460f94c4fe41/html5/thumbnails/76.jpg)
76
EXPANSION COMPLETED
ptr size is 8
5 7 4 2
Array is ready for more elements, using the same “array name”, ptr.