I have a question. Let's say that I have a struct, say something like:
struct myData
{
int a;
int b
} x, y ;
Then, I create a pointer that points to x, for example:
myData * x_ptr = &x;
So I know that x_ptr point to the memory location where x is stored. So I can find the memory location for the whole struct. But, let's say I want to find the memory location for the member a of the struct variable x. How do I do that ?
For me, it would seem natural to do something like this:
x_ptr.a
Now, I know that this dosen't work. When I imagine how the variables are stored in the memory of the computer I'm thinking of a box with something in it. So for a struct, it would be a bigger box which contains two members, in my case a and b. So, is the memory location of a and b the same as the memory location for the whole "box" ? That's why I can't acces the memory location of x.a ?
I'm trying to understand pointers, and I quickly gained an idea of how things work, but this bothers me. Could somebody answer me, please ? Thank you! :)