-3

What is the difference between an array pointer and a pointer array in C?

Dipto
  • 2,720
  • 2
  • 22
  • 42
karthzDIGI
  • 393
  • 1
  • 4
  • 15

2 Answers2

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