首页 > 编程语言 > 详细

C++常见题

时间:2014-09-27 00:11:00      阅读:264      评论:0      收藏:0      [点我收藏+]

大端小端问题:内存从左到右读史从高低址到低地址,故为小端

字节对齐问题:常见的32位系统

struct A
{
int a;
char b;
short c;
};
struct B
{
char b;
int a;
short c;
};
A占8字节,B占12字节。

union{

int a;
char b[2];
}n;


int main(){
n.b[0]=1;
n.b[1]=1;
printf("%d",n.a);
system("pause");
return 0;

}

这里输出257,可见char的数组是右对齐的。

 

对于

unsigned int i = -1;
printf("%d\n", i );

输出-1;

 

C++常见题

原文:http://www.cnblogs.com/shaozhiheng/p/3995780.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!