请问这道关于结构体指针的题目是怎么算?
structtagABC{charcB;charsC;charcD;char1A;}*pAbc;pAbc=0x100000;那么pAbc+0x100=;(ULONG)pA...
struct tagABC
{
char cB;
char sC;
char cD;
char 1A;
}*pAbc;
pAbc=0x100000;
那么pAbc+0x100= ;(ULONG)pAbc+0x100= ;
(ULONG*)pAbc+0x100= ;(char *)pAbc+0x100= ; 展开
{
char cB;
char sC;
char cD;
char 1A;
}*pAbc;
pAbc=0x100000;
那么pAbc+0x100= ;(ULONG)pAbc+0x100= ;
(ULONG*)pAbc+0x100= ;(char *)pAbc+0x100= ; 展开
1个回答
展开全部
结构体中声明有错误, 1A不能是变量
sizeof(struct tagABC) = 4
本题根据系统的不同结果也不尽相同, 这儿假设系统是32位的,且char占一个字节(byte),unsigned long 占4个字节
pAbc是struct tagABC类型的指针,所以每次pABC+1时都是加一个struct tagABC大小的值,即要加4
所以pAbc+0x100 = 0x100000 + 4*0x100 = 0x100000 + 0x400 = 0x100400
(ULONG)pAbc将pAbc强制转为无符号长整型,所以直接加
所以(ULONG)pAbc+0x100= 0x100100 ;
(ULONG*)将pAbc强制转为无符号长整型的指针,且sizeof(unsigned long) = 4
所以pAbc+0x100 = 0x100000 + 4*0x100 = 0x100000 + 0x400 = 0x100400
(char *)pAbc将pAbc强制转为char型指针, sizeof(char)=1
所以(ULONG)pAbc+0x100= 0x100100
sizeof(struct tagABC) = 4
本题根据系统的不同结果也不尽相同, 这儿假设系统是32位的,且char占一个字节(byte),unsigned long 占4个字节
pAbc是struct tagABC类型的指针,所以每次pABC+1时都是加一个struct tagABC大小的值,即要加4
所以pAbc+0x100 = 0x100000 + 4*0x100 = 0x100000 + 0x400 = 0x100400
(ULONG)pAbc将pAbc强制转为无符号长整型,所以直接加
所以(ULONG)pAbc+0x100= 0x100100 ;
(ULONG*)将pAbc强制转为无符号长整型的指针,且sizeof(unsigned long) = 4
所以pAbc+0x100 = 0x100000 + 4*0x100 = 0x100000 + 0x400 = 0x100400
(char *)pAbc将pAbc强制转为char型指针, sizeof(char)=1
所以(ULONG)pAbc+0x100= 0x100100
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询