sizeof一些事
2019-05-26 10:11 Gizing 阅读(179) 评论(0) 编辑 收藏 举报sizeof()返回一个变量或者类型大小(单位是字节)
struct rec //x64系统
{
int* a; //8字节
char b; //4字节,因为对齐
int c; //x64系统,4字节
};
sizeof(rec) = 16
// x64系统
char *a= "abcd\n"; //sizeof(a) =8
char b[10] ="abcd\n"; //sizeof(b) = 10
char c[][10] = {"aaa", "ccc"}; // sizeof(c)=20
char *d[10] = {"aaa", "ddd"}; //sizeof(d) = 80
x86下各数据类型及指针大小(单位是字节)
Size of char is: 1
Size of unsigned char is: 1
Size of signed char is: 1
Size of int is: 4
Size of short is: 2
Size of long is: 4
Size of long int is: 4
Size of signed int is: 4
Size of unsigned int is: 4
Size of unsigned long int is: 4
Size of long long int is: 8
Size of unsigned long long is: 8
Size of float is: 4
Size of double is: 8
Size of long double is: 8
Size of (void *) is: 4
Size of (char *) is: 4
Size of (int *) is: 4
Size of (long *) is: 4
Size of (long long *) is: 4
Size of (float *) is: 4
Size of (double *) is: 4
所有指针都是占4字节
x64下各数据类型及指针大小(单位是字节)
Size of char is: 1
Size of unsigned char is: 1
Size of signed char is: 1
Size of int is: 4
Size of short is: 2
Size of long is: 8
Size of long int is: 8
Size of signed int is: 4
Size of unsigned int is: 4
Size of unsigned long int is: 8
Size of long long int is: 8
Size of unsigned long long is: 8
Size of float is: 4
Size of double is: 8
Size of long double is: 16
Size of (void *) is: 8
Size of (char *) is: 8
Size of (int *) is: 8
Size of (long *) is: 8
Size of (long long *) is: 8
Size of (float *) is: 8
Size of (double *) is: 8
所有指针都是占8字节