http://blog.csdn.net/lnever/archive/2009/01/03/3695590.aspx
转自:http://topic.csdn.net/u/20081121/21/02fd5ae1-ff29-447c-8c6d-67da15e9ff0e.htmlsizeof:
i.在32位操作系统中,基本数据类型
类型 字节长度
char 1
short 2
short int 2
signed short 2
unsigned short 2
int 4
long int 4
signed int 4
unsigned int(unsigned) 4
long 4
unsigned long 4
float 4
double 8
void* 4 (所有指针类型长度都一样)(char*,int*,float*,double*)
enum 4
ii.在32位操作系统中,定义或函数中的大小
char a[]="hello";
char b[100];
char *p=a;
类型 字节长度
sizeof(a) 6
sizeof(b) 100
sizeof(p) 4
void Func(char a[100])
{
sizeof(a); //4
}
#pragma pack(1)
struct A
{
int i;
char j;
};
sizeof(A) //5
#pragma pack(1)
struct A
{
int o;
int j;
union
{
int i[10],j,k;
};
};
sizeof(A) //48
#pragma pack(1)
struct A
{
enum day{monring, moon, aftermoon};
};
sizeof(A) //1
sizeof(A::day) //4
0 评论:
发表评论