What is the difference between an array pointer and a pointer array in C?
Asked
Active
Viewed 408 times
-3
-
1This is probably of use to you Ksindev. http://stackoverflow.com/questions/1641957/is-array-name-a-pointer-in-c – Randy Howard Mar 28 '13 at 08:54
-
Without a code example your question is a little ambiguous. Are you asking about the difference between "a pointer to an array" and "an array of pointers"? – CB Bailey Mar 28 '13 at 08:54
-
If you figure out what each of those are, the difference will follow. – Jim Balter Mar 28 '13 at 08:58
-
1It's like the difference between five people in one car and one person in five cars. (One is distinctly more common than the other.) – Kerrek SB Mar 28 '13 at 09:04
-
@KerrekSB Especially if it's the same person. :-) – Jim Balter Mar 28 '13 at 09:47
2 Answers
2
Array pointer points to array, and pointer array is array of pointer, that may point to somewhere.
int array[10]; // `array` is an array pointer
int* pointers_array[10];

Alex
- 9,891
- 11
- 53
- 87
-
1`array` isn't an array pointer, it's the name of an array. If you do `&array` you get a pointer to an array, not a pointer to a pointer. – CB Bailey Mar 28 '13 at 09:37
2
An array pointer is a pointer referring to an array. You could access items using pointer arithmetic, and in the opposite direction you could use pointer to access items in an array manner.
int array [20];
int a = *(array + 10);
int b = array[10];
int *p;
p = array;
int c = *(p + 10);
int d = p[10];
all approaches will work, a,b,c,d will get to same value. However, use the different approaches with care. The difference between array and p is
p ++; // allowed
array ++; // fail
An array of pointer just mean your array items are pointers (to what type however).
char* parray[20];
This array holds 20 pointers to "char" or depending of interpretation to "strings"
So parray is the array pointer of an array of char pointers

stefan bachert
- 9,413
- 4
- 33
- 40