核心提示:1.Sizeof 定义:sizeof是一个操作符,作用是返回一个对象或一个类型所占的内存字节数.2.常见sizeof的值1.变量char a; sizeof(a) = 1;short a;sizeof(a) = 2;int a;sizeof(a) = 4;long a; sizeof(a) = 4;...
1.Sizeof 定义:sizeof是一个操作符,作用是返回一个对象或一个类型所占的内存字节数. 2.常见sizeof的值 1.变量 char a; sizeof(a) = 1; short a; sizeof(a) = 2; int a; sizeof(a) = 4; long a; sizeof(a) = 4; float a; sizeof(a) = 4; double a; sizeof(a) = 8; long int a; sizeof(a) = 4; long double a; sizeof(a) = 8; 2.指针 char *p; short *p; int *p; long *p; double *p; sizeof(p) = 4; char *p = (char *)malloc(100); sizeof(p) = 4; 3.数组 char array[10]; sizeof(array) = 1*10 = 10; int array[10]; sizeof(array) = 4*10 = 40; char array[]={"12345"}; |
|