c - Why is this code able to access a null pointer without causing a crash? -


i have come across following piece of code, finds offset of member within structure. not able make out why not crash, though tries derefer null pointer

struct a_ {     int a;     int b; };  int main() {     int offset = &(((struct a_ *) 0x0)->b);     printf ("offset of b = %x\n", offset); }   output = 4 

however not able make out why not crash, though tries derefer null pointer.

you forming invalid address undefined behavior there no dereference of null pointer because of & operator cancels dereference.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -