凹凸Man

When you're lying, it's hard to tell a story backwards, because there's no real memory of what happened.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

数据长度

Posted on 2010-05-19 09:54  凹凸Man  阅读(1020)  评论(0)    收藏  举报

结构体数据长度:4字节对齐

1、

typedef struct tagA

{

    shorta;

   char  b;

}TA;

sizeof(TA)  = 4;

 

2、

typedef struct tagA

{

    shorta;

}TA;

sizeof(TA) = 2;

 

3、

typedef struct tagA

{

   char  b;

}TA;

sizeof(TA)  = 1;

4、

typedef struct tagA

{

    shorta;

   char  b;

    shorta;

   char  b;

}TA;

sizeof(TA)  = 8;

 

 

几种常见的数据类型包括:int, short int,long int, double,float,char,可以划分数值类(整型、浮点型),字符类,各种数据类的字长一般与机器字长相关联。
1、 int, short int, long int(默认为带符号类型signed):int一般为一个机器字长,short int为半个机器字长,而在32位机器中,long int 与 int 有一样的字长。所以对于32位机器(比较常见)来说,int---32位,short int –16位,long int ---32位(在16位机器中亦是)。
2、 float, double float, longdouble:float通常一个机器字长(32位),double是两个机器字长(64位),longdouble是三个或四个字长,有时也会市两个机器字长(64位)。
3、 char: 8位,一个字节