NULL pointer dereference in C
Posted
by
user554125
on Stack Overflow
See other posts from Stack Overflow
or by user554125
Published on 2010-12-26T04:48:59Z
Indexed on
2010/12/26
4:54 UTC
Read the original article
Hit count: 206
hey ive got this piece of code. It dereferences a null pointer here. But then there is an and with unsigned int. I really dont understand the whole part. Can someone explain the output.??
struct hi
{
long a;
int b;
long c;
};
int main()
{
struct hi ob={3,4,5};
struct hi *ptr=&ob;
int num= (unsigned int) & (((struct hi *)0)->b);
printf("%d",num);
printf("%d",*(int *)((char *)ptr + (unsigned int) & (((struct hi *)0)->b)));
}
The o/p i get is 44 .But how does it work?
© Stack Overflow or respective owner