Originally Posted by mr.anandc
Here my doubt is, if ptr value is 0 which is NULL, why access to b using ptr (ptr->b) is not crashing .


That is Now your Intelligent question!!!
#define offsetof(s,m) (size_t)&(((s *)0)->m)
#define Off(i,j)  ((i*)0)->j

struct Data
 int a;
 int b;

int main()
  int OffSet=offsetof(Data, b);
  printf("%d", OffSet) ;
  return 0;

In above  code , You are only getting the address not accessing.

int main()
  int Add=Off(Data , b);
  printf("%d", Add) ;
  return 0;
In this code , now you are accessing so segmentation fault will come.

Last edited by shabbir; 9May2008 at 11:29.. Reason: Code block