Original Post
Is it possible to access the individual elements of a structure using some offset from the current memory address?
For example, if I had a struct that was as such:
Instead of calling a->y I was wondering if there was a way I could do something like *(a+offset) where offset is sizeof(int) or something, and then it would access the y element. So far nothing I do seems to work. I could've sworn that my understanding of the way struct was laid out meant that the struct was contiguously stored in memory or something.
For example, if I had a struct that was as such:
typedef struct {
int x;
int y;
int z;
} BALL;
BALL *a = malloc(sizeof(BALL));
Instead of calling a->y I was wondering if there was a way I could do something like *(a+offset) where offset is sizeof(int) or something, and then it would access the y element. So far nothing I do seems to work. I could've sworn that my understanding of the way struct was laid out meant that the struct was contiguously stored in memory or something.