I have a very confusing question to ask and it is the difference between array of pointers & pointer to an array. I want to understand this concept very well so please please do help me understand this concept. I'll start with what I have understood about array of pointers. An array of pointers is possible beacuse pointers are similiar to variables.
*pt is an array of 3 pointers i.e 3 locations are set aside for the storage of the addresses of 3 variables.
pt corresponds to the address of the 1st element and
*pt gives us the value of the 1st element. Now when we utilize array of pointers for 2-D arrays, the addresses stored in the array are starting addresses of 1-D arrays and hence we can access the entire 2-D array using the array of pointer construct i.e. if the address of the 1-D array is stored in pt then the location of the 1st element of the 3rd array can be written as:
*(*(pt+2)+0), hence all the elements of all the arrays an be accessed in this manner by proper indexing. Another added advantage is that we can have variable length arrays. Am I right regarding this? When the concept of pointers to array comes all hell breaks loose. Pointers to arrays are declared as
(*ptr). I don't understand what is the difference between this definition and the one I gave above. I don't understand what is stored in the array of
(*ptr)? Is it addresses of arrays?? If it is then how is it any better than array of pointers?
Edited 3 Years Ago by anumash