当前位置: 代码迷 >> C语言 >> 2+2+14+4=24??不相信的进来看
  详细解决方案

2+2+14+4=24??不相信的进来看

热度:358   发布时间:2006-04-09 12:22:00.0
2+2+14+4=24??不相信的进来看

#include<stdio.h>

typedef struct
{
short unsigned dataIcon;
short unsigned dataNum;
char empty[14];
long dataDate;
}DAILYITEM;

main()
{ printf("%d=%d+%d+%d+%d\n",sizeof(DAILYITEM),
sizeof(short unsigned),
sizeof(short unsigned),
sizeof(char)*14,
sizeof(long));
return 0;
}

编译器 VC6 输出:
24=2+2+14+4
Press any key to continue

搜索更多相关的解决方案: continue  include  return  编译器  

----------------解决方案--------------------------------------------------------
扔掉!我的是22
----------------解决方案--------------------------------------------------------

字节对齐问题

#include<stdio.h>
#pragma pack(1) //强制1字李对齐
typedef struct
{
short unsigned dataIcon;
short unsigned dataNum;
char empty[14];
long dataDate;
}DAILYITEM;
#pragma pack( ) //恢复
main()
{ printf("%d=%d+%d+%d+%d\n",sizeof(DAILYITEM),
sizeof(short unsigned),
sizeof(short unsigned),
sizeof(char)*14,
sizeof(long));
return 0;
}


----------------解决方案--------------------------------------------------------
  相关解决方案