Originally Posted by
n@bu
When a pointer to an array increments to iterate across the array. Does this action create an array of pointers like:
No, it is just the value of the pointer changing to point to the next element, which happens to be an array.
Originally Posted by
n@bu
Also, my other question, if the memory block, right after ptr is used, by some other variable, does ptr+1 use the next open memory slot, or does the program throw an error, at compile time?
Nothing much: it means ptr+1 points to one-past-the-end of the array, which is fine as long as you make no attempt to dereference it. This is useful for iterating, e.g.,
Code:
const int numbers[] = {0, 1, 2, 3};
const int *ptr = numbers;
const int *end = numbers + sizeof(numbers) / sizeof(numbers[0]);
for (; ptr != end; ++ptr)
{
printf("%d\n", *ptr);
}