Accessing structure elements using pointers
- by Arun Nadesh
Hi Everybody,
Greetings!
I got surprised when the following program did not crash.
typedef struct _x{
int a;
char b;
int c;
}x;
main()
{
x *ptr=0;
char *d=&ptr->b;
}
As per my understanding the -> operator has higher precedence over & operator. So I expected the program to crash at the below statement when we try to dereference the NULL pointer tr.
char *d=&ptr->b;
But the statement &ptr->b evaluates to a valid address. Could somebody please explain where I'm wrong?
Thanks & Regards,
Arun