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[3]
is an array of 3 pointers i.e 3 locations are set aside for the storage of the addresses of 3 variables. pt[0]
corresponds to the address of the 1st element and *pt[0]
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[2] 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)[4]
. 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)[4]
? Is it addresses of arrays?? If it is then how is it any better than array of pointers?
anumash 0 Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.