69,371
社区成员
发帖
与我相关
我的任务
分享
int type = *(int *)p;
#include "stdafx.h"
#include "stddef.h"
struct A
{
int size;
int type;
char cz;
float flt;
int nvalue;
};
int _tmain(int argc, _TCHAR* argv[])
{
struct A aa;
aa.size = 12;
aa.type = 23;
aa.cz = 'b';
aa.flt = 125.1234567f;
aa.nvalue = 55;
//get the pointer
char* ptr = (char*)&aa;
size_t offset = offsetof( A, nvalue );
ptr += offset;
int nV = (int)*ptr;
return 0;
}
// testCSDN2.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
struct A
{
int size;
int type;
char cz;
float flt;
};
int _tmain(int argc, _TCHAR* argv[])
{
struct A aa;
aa.size = 12;
aa.flt = 5.8f;
aa.type = 23;
aa.cz = 'b';
char* ptr = (char*)&aa;
char* p = ptr;
p += sizeof(int);
int tpe = (int)(*p);
return 0;
}
struct A
{
int size;
int type;
};
int main()
{
struct A aa;
aa.size=8;
aa.type=18;
char *ptr;
ptr = (char *)&aa;
printf("%d",*(int *)(ptr+offsetof(A,type)));
return 0;
}
struct aa{
int a;
int b;
}bb={1,3};
int main()
{
char *ptr=(char *)&bb;//要加上&符号吧,指针么
printf("%d,%d",*(int *)ptr,*((int *)ptr+1));
#include <stdio.h>
struct A
{
int size;
int type;
} ;
int main(void)
{
struct A test;
test.type = 0x12345678;
printf("%x\n", *(int*)((char*)&test+4));
return 0;
}
#include <stdio.h>
#include <string.h>
struct A
{
int size;
int type;
};
int main()
{
struct A aa;
aa.size=10;
aa.type=20;
char *ptr=(char *)&aa;
printf("%d\n",*((int *)(ptr+4)));
return 0;
}