结构指针返回结构成员的起始字节 [英] Structure pointer returning the start byte of member of structure

查看:69
本文介绍了结构指针返回结构成员的起始字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

返回结构成员起始字节的结构指针 我不知道它是如何工作的.请请一些人帮助我了解这一点.

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;
 }

输出为16

推荐答案

该程序实际上应该崩溃,因为指针m没有指向有效的内存位置.下面的代码可以给出结果.

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将给出十六进制地址值.

%x will give hexadecimal address value.

这篇关于结构指针返回结构成员的起始字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆