指针运算的结构 [英] Pointer arithmetic for structs

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

问题描述

由于包含一张双人床和3个int变量(4个变量在所有)一个结构的定义,如果p是一个指针,这个结构用一个值为0x1000,并p ++有什么价值呢?

这是不是一门功课的问题,所以不用担心。我只是想以prepare一个测试,我想不通这种做法的问题。谢谢

这是C.是的,我想p的值就递增了。这是一个32位的机


解决方案

 结构foobar的* P;
P = 0×1000;
p ++;

是相同的

 结构foobar的* P;
P = 0×1000 +的sizeof(结构FOOBAR);

Given a struct definition that contains one double and three int variables (4 variables in all), if p is a pointer to this struct with a value 0x1000, what value does p++ have?

This is not a homework problem, so don't worry. I'm just trying to prepare for a test and I can't figure out this practice problem. Thanks

This is in C. Yes I want the value of p after it is incremented. This is a 32-bit machine

解决方案

struct foobar *p;
p = 0x1000; 
p++;

is the same as

struct foobar *p;
p = 0x1000 + sizeof(struct foobar);

这篇关于指针运算的结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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