Let me blow your mind....
>> There is a difference in question 1:
>> a.) array of pointers
>> b.) pointer to an array
>> BIG DIFFERENCE!
No Difference.... follow me here cause this get's convoluted..
char *a[] you say is an arrray of zero ponters. I say your right, but I say this is exactly the same as a pointer to a pointer.
char (*a)[] you say is a pointer to an array of zero elements. I say that you're right again, but that is also a pointer to a pointer.
An array is a pointer with memory associated with it. Or a pointer with memory associated with it is an array.... They are the same and can be treated as such.. Likewise an array with no memory associated with it is merely a pointer... Check it out...
// I define a structure
typedef struct __MYSTRUCT
{
int a;
int b;
} *PMYSTRUCT, MYSTRUCT;
void main()
{
// declair variables
MYSTRUCT *pPointer = NULL;
MYSTRUCT Structure[100];
// associate memory with my pointer
pPointer = new MYSTRUCT[100];
// Loop through and initialize my arrays..
for( int i = 0; i < 100; i++)
{
pPointer[i].a = 1; // <- pointer is an array
Structure[i].a = 1; // <- array is an array
(pPointer+i)->b = 2; // <- pointer is also a pointer
(Structure+i)->b = 2; // <- array is also a pointer
}
}
Does that blow your mind or what? An Array is just a pointer with memory associated with it. Character arrays are the same.
>> char a[];
An array with no memory associated with it is equal to a pointer with no memory associated with it.
The '*' is a derefference syntax.
The '[n]' syntax adds n onto the pointer and then derrefferences. If their is no n the '[]' is equivelent to the '*' command.
Think about it, it's a powerful technique for refferencing dynamic data structures.