内存对齐的一道面试题目

来源:互联网 发布:测试手机信号强度软件 编辑:程序博客网 时间:2024/05/23 16:19
今天浏览网页的时候,看到了一道笔试的题目,代码如下
#include <stdio.h> typedef struct {int x;char y;long z;short a;void *ptr_x;}str_1;int main(int argc,char **argv){printf("size of str_1=%d Byte\n\r",sizeof(str_1));return 0;}


 

请回答该句打印的结果?

解答: 在32位机子下,

 int 4  Byte

char 1 Byte 

long 4 Byte

short 2 Byte

void * 4Byte

然后 4(4)+1(4)+4(4)+2(4)+4(4)= 20 Byte  括号内为实际占用的内存

0 0
原创粉丝点击