P
prix prad
Hi,
I have the foll. program. Shoudn't the program crash when the
NULL pointer is typecast to structure and we try to get the address
of one of its members.
I mean how is '&p->c' supposed to work when p is NULL?
<snip>
#include <stdio.h>
typedef struct temp
{
int f;
int k;
} TEMP;
typedef struct abc_
{
int a;
TEMP b;
int c;
} abc;
main() {
void *q = NULL;
abc *p = NULL;
int i = (int) (&((abc *)NULL)->c);
int j = (int) &((abc *)0)->c;
int k = (int) &((abc *)q)->c;
int l = (int) &p->c;
printf("\n i is %d, j is %d, k is %d, l is %d, m is %d", i, j, k,
l, &p);
printf("\n Hi: Size of abc is %d\n ", sizeof(abc));
return (1);
}
</snip>
The o/p is
i is 12, j is 12, k is 12, l is 12, m is -4195224
Hi: Size of abc is 16
I have the foll. program. Shoudn't the program crash when the
NULL pointer is typecast to structure and we try to get the address
of one of its members.
I mean how is '&p->c' supposed to work when p is NULL?
<snip>
#include <stdio.h>
typedef struct temp
{
int f;
int k;
} TEMP;
typedef struct abc_
{
int a;
TEMP b;
int c;
} abc;
main() {
void *q = NULL;
abc *p = NULL;
int i = (int) (&((abc *)NULL)->c);
int j = (int) &((abc *)0)->c;
int k = (int) &((abc *)q)->c;
int l = (int) &p->c;
printf("\n i is %d, j is %d, k is %d, l is %d, m is %d", i, j, k,
l, &p);
printf("\n Hi: Size of abc is %d\n ", sizeof(abc));
return (1);
}
</snip>
The o/p is
i is 12, j is 12, k is 12, l is 12, m is -4195224
Hi: Size of abc is 16