Well, I think it may be a stupid question, but I want to know how this code works.
Here is an example code.
typedef struct {
int first;
int second;
int third;
}mypointer;
int main()
{
mypointer *mp = 0;
printf("this is third member : %p\n", &mp->third);
return 0;
}
I guess it should return segmentation fault, because pointer mp points to zero address and points to invalid memory address. However, actual result is different.
this is third member : 00000008
I know, it is bad, but it works.
So, I guess that when I points to struct member whatever struct is allocated or not, I am able to get address of struct member.
Is this correct?