Structure pointer returning the start byte of memb

2019-09-26 03:55发布

Structure pointer returning the start byte of member of structure .I wondered how it works. PLease some one help me to get know about this.

 #include <stdio.h>

 typedef struct node {
  char mem;
  double mem2;
  char mem3;
  int mem4;
  char mem5;
  char mem6;
 }NODE;
 int main()
 {
     NODE * m;
     printf("%u",&m->mem3);
     return 0;
 }

Output is 16

1条回答
放我归山
2楼-- · 2019-09-26 04:51

The program actually should crash because pointer m is not pointing valid memory location. Below code can give the result.

NODE M;
NODE *ptr = &m;
Printf(“%x”, &ptr->mem3);

%x will give hexadecimal address value.

查看更多
登录 后发表回答