I have a generic struct declared and an array of these structs as given below:
struct A
{
int x,y,z;
char a,b,c;
};
struct A *str_arr[5];
From my understanding str_arr is a pointer to a block of memory which stores pointers to the 5 structs in sequential order and therefore these pointers can be accessed via pointer arithmetic or array indexing as:
struct A *str_a = str_arr[1]; // points to 2nd struct?
struct A *str_b = str_arr + 2*sizeof(struct A*); // points to 3rd struct?
However, these 5 structs might not be in sequential memory?
printf("%p\n", str_arr); // prints memory location of start of str_arr pointers?
printf("%p\n", str_arr[1]) // prints memory location of 2nd struct?
printf("%d\n" str_arr == &str_arr[0]) // prints 1?
I would just like clarification that my understanding is correct with all of the points I have raised.
str_arris array of pointer tostruct A(five pointer tostruct A).int a[42]do not have to be in sequential order. They are whatever you put in there.