-4

Please tell me what is the difference between Array of Pointer and Pointer to Array, specially in c language

  • 1
    Are you sure you mean "pointer of an array" and *not* pointer *to* an array? :) – babon Dec 14 '17 at 18:03
  • 1
    One points to a collection of things, one is a collection of things that point to other things (aka a collection of pointers). – byxor Dec 14 '17 at 18:08

1 Answers1

0

Let T be a random type (int, long int, double, enum ecc..) then:

int n=3;
T arr[n];
T*p=arr;

p is a pointer to the first elemente of T array arrso you can access the first element of your array like this:

arr[0]="whatever you want but a r-value"

or

p=...

It's an easy way to move around your array without indexes and a great solution to pass variables by value. Keep in mind that the pointer has, as r-value, the l-value of the pointed object, when the pointer is dereferenced we obtain the pointed object. So writing p+1 means to move the pointer to the second element of your array. Arrays of pointers actually are a collection of this object (a pointer to a variable or to another data structure). For example you can have an array of int pointers to track all the elements of a lined list. Since you did not define each pointer, thay are unreferred so it can be a dangerous way to code.