|
|
|
|
|
|
|
cout << ** In CopyFrom function, not enough memory
<< for << size << elements ** << endl;
exit(1);
}
for (i = 0; i < size; i++)
arr[i] = array2.arr[i];
} |
|
|
|
|
|
|
|
|
Programs that use pointers are more difficult to write and debug than programs without pointers. Indirect addressing never seems quite as normal as direct addressing when you want to get at the contents of a variable. |
|
|
|
|
|
|
|
|
The most common errors associated with the use of pointer variables are |
|
|
|
|
|
|
|
|
1. confusing the pointer variable with the variable it points to |
|
|
|
|
|
|
|
|
2. trying to dereference the null pointer or an uninitialized pointer |
|
|
|
|
|
|
|
|
Let's look at each of these in turn. |
|
|
|
|
|
|
|
|
If ptr is a pointer variable, care must be taken not to confuse the expressions ptr and *ptr. The expression |
|
|
|
|
|
|
|
|
accesses the variable ptr (which contains a memory address). The expression |
|
|
|
|
|
|
|
|
accesses the variable that ptr points to. |
|
|
|
|
| |
|
|
|
|
Copies the contents of ptr2 into ptr1. |
|
|
|
| | |
|
|
|
|
Copies the contents of the variable pointed to by ptr2 into the variable pointed to by ptr1. |
|
|
|
| | |
|
|
|
|
Illegalone is a pointer and one is a variable being pointed to. |
|
|
|
| | |
|
|
|
|
Illegalone is a pointer and one is a variable being pointed to. |
|
|
|
|
|
|
|