As already shown pointers and arrays are similar.
char l_array; EDIT: char *l_array = new char; char *l_pointer = l_array;
And if you deal with c style strings you might end up looping through an array in just this way.
for( l_pointer = l_array ; *l_pointer != 0 ; l_pointer++ )
cout << *l_pointer;
This code will print the contents of the array, stopping when the null character '0' is reached at the end.
You don't want to use the array itself in this situation.
for( ; *l_array != 0 ; l_array++ )
cout << *l_array;
In the code above, the contents of the array will still be printed. Note however, that the array itself will be pointing to the last element in the array and the rest of the contents of the array will be effectively lost.
In example 1 the pointer is assigned the address at which the array is also pointing to. At the end of each iteration of the loop, the pointer is then incremented by the size of one char, thus causing the pointer to 'point at' the next element in the array.
In example 2 there is no intermediary pointer. The array itself has been incremented by the size of one char and so now has a new first element. It would be possible then to address this array erroneously and write beyond the original array's boundary through a statement such as:
l_array = 'i';
Were this array created using the syntax:
these problems would not be present.
In cases such as the one shown above, and when the array would have been passed as a parameter, such as:
void someFunc( char pData )
It is still possible to encounter this error.