69,382
社区成员
发帖
与我相关
我的任务
分享
struct abcd
{
char c;
int d;
int a ;
char b;
};
#include <stdio.h>
struct abc
{
int a ;
char b;
char c;
int d;
};
struct abcd
{
int a ;
char b;
int d;
char c;
};
void main()
{
printf("%d\n", sizeof(abc)); //输出12
printf("%d\n", sizeof(abcd));//输出16
}
#include <iostream>
using namespace std;
struct send
{
char a;
int b;
short c;
char d;
short e ;
};
struct rev
{
char a;
int b;
short c;
char d;
short e ;
};
int main()
{
char Buff[20] ;
char Msg[20];
send s = {'a', 1234, 12, 'b', 34};
rev r;
memcpy(Buff, &s, sizeof(s));
memcpy(Msg, Buff, sizeof(s));
memcpy(&r, Msg, sizeof(r));
cout << r.a <<endl;
cout << r.b <<endl;
cout << r.c <<endl;
cout << r.d <<endl;
cout << r.e <<endl;
return 0;
}
struct abcd //16
{
char a;
int b;
short c;
char d;
short e
};
struct abcd
{
char a;
int b;
short c;
struct d; //空结构体,大小为1
};
struct dcba
{
struct d;//空结构体,大小为1
short c;
int b;
char a;
};
char a; //b不能跨格,所以a独占一格
int b;//独占一格
short c;//占一个的2字节
struct d; //不跨格,占一个的1字节
struct ab //4
{
int a;
};
struct abcd //16
{
char a;
int b;
short c;
ab d;
};
struct dcba //16
{
ab d;
short c;
int b;
char a;
};
struct abc //12
{
ab d;
int b;
short c;
char a;
};
struct abcd
{
char a; //1
int b; //4
short c; //2
struct d; //1
struct dcba
{
struct d;//1
short c; //2
int b; //4
char a; //1
};