65,210
社区成员
发帖
与我相关
我的任务
分享#include <stdio.h>
#include <string.h>
#pragma pack(push,1)
struct a {
float b;
int d;
char c;
};
#pragma pack(pop)
struct a temp,test;
unsigned char buf[sizeof(struct a)];
int main() {
temp.b=0.1f;
temp.d=23;
temp.c='4';
memcpy((void *)buf,(void *)&temp,sizeof(struct a));
memcpy((void *)&test,(void *)buf,sizeof(struct a));
printf("%3.1f %d %c\n",test.b,test.d,test.c);
return 0;
}
//0.1 23 4#include <stdio.h>
#include <string.h>
#pragma pack(push,1)
struct a {
float b;
int d;
char c;
};
#pragma pack(pop)
struct a temp,test;
unsigned char buf[sizeof(struct a)];
int main() {
temp.b=0.1f;
temp.d=23;
temp.c='4';
memcpy((void *)&test,(void *)&temp,sizeof(struct a));
printf("%3.1f %d %c\n",test.b,test.d,test.c);
return 0;
}
//0.1 23 4