-
pointer initialisation
damm this is doing my head in, I know it's probably a simple answer i should know myself but i cant figure it out
I want to iniialise a pointer to an array of structures
this is what i've tried
Code:
struct mystruct array[10], *array_ptr;
array_ptr = array; /* this dont work */
array_ptr = &array; /* or this */
array_ptr = array[0] /* you guessed it */
help before its to late and i jump of my roof
:D
-
The first should have worked
Code:
struct mystruct {
int a;
};
int main ( ) {
struct mystruct array[10], *array_ptr;
array_ptr = array; /* this dont work - it does here */
array_ptr = &array; /* or this - because it's a pointer to the whole array */
array_ptr = array[0]; /* you guessed it - this is an element of the array */
array_ptr = &array[0]; /* but this is a pointer to the first element - So this is OK */
return 0;
}
-
Thaks salem the first method works for me now.
must be my compilers time of the month.
:D