Ok.
Basically, ive written this in this board three times in the past week or maybe a month ago lol..i was on holiday for three weeks so time passed...
Let A be some typename, such that you can declare an object of type A eg: A a,b,c;
Let a be an instance of type A, ie A a;
Let p be an instance of an A*, ie A *p;
Let P be an instance of an A**, ie A **P;
*p means 'whats at the address of' p
&a means 'the address of' a
*a would mean 'whats at the address of' a, but as 'a's not an address thats invalid. (sorry if im going too simple..but uim going to anyway).
&p means 'the address of' p, which is perfectly legitamate, as a pointer is an address stored somewhere in memory: To address a pointer is somewhat unusual, as oto access the data at the very endof the chain of pointers you would need to get the pointer at the address of the first pointer, and then get the variable at the address of it ie **P.
Now, p is not an array.
But if you were to go p[4] = 5; /* assuming an A can be assigned the value 5 */ that would be syntaxically correct.
What is does, is takes the value of p (an A*, ie an address), and uses the A, that is 4 A's along in memory (ie 4*sizeof(A) in bytes ) from the A that p addresses.
When you are using an array, the array variable is actually equivalent in many respects (indeed every explicit respect).
Let array be an array of A, ie: A array[5];
array itself can actually be used just like a pointer to a[0], because, well thats what it is.
if you were to go p = array + 1;, you could go p[0]=5;, and it would be the same as going array[1]=5;
//NOTE: when you add one to a pointer, it increases the physical address which is references by the size of the object it points to, ie p[0] IS *p, p[1] IS *(p+1), p[2] IS *(p+2)
Arrays, being sequential only need to have the address of their first variable stored, as every other element in the arrays position can be calculated from that first address
When looping through an array, it can be more efficient to do , instead of this
int array[5];
for( int t=0; t<5 ; ++t )
{
array[t] = /*..*/
}
to use a pointer, and increment that:
int array[5];
for( int*ptr=array; ptr<array+5 ; ++ptr )
{
*ptr = /*..*/
}
Written more understandably:
int array[5];
int*pFirst = &array[0];
int*pLast = &array[4];
for( int*ptr=pFirst; ptr<=pLast ; ++ptr )
{
*ptr = /*..*/
}
Now, with everything in this topic, thinking hard enough there is no pointer issue you cant resolve.
To figure out what int*p[] would mean, just imagine an int* is another type: alias it in your mind.
Say an int* is actually a type called X.
X p[] would be an array of X's, so p would be a pointer to the first X in the array.
The next X in the array would be the X one X after that in main memory, ie p[1], or *(p+1).
Replacing X with int*, what we have, is a pointer to an int*. There is another int* after that, such that p[1] is another int*, as is p[2].
And as p[0], p[1], p[2] ... OR *(p+1), *(p+2), *(p+3) ... are pointers, you can put '*' infront of them to access the int at their address ie:
*(p[0]) = 5; is legal.
There.
If you have any more Q's, i cant imagine i could do anything more to help other than draw some boxes and label them p[0], p[1], p[2], though judging by people ive worked with before, that actually helps ALOT.