sizeof()求取参数在内存中的字节数大小。

sizeof在对指针和数组的求取中需要注意的地方;

#include<stdio.h>

int main()

{

char *p = NULL;

char arr[10];

    char str[]="hello";

int a, b, d, e, f, g,h;

a = sizeof(*p);//指针类型。    a=1;

b = sizeof(p);//sizeof求任何指针都是4个字节。 b=4;

d = sizeof(arr);//数组元素所占用空间; d=10;

e = sizeof(arr[10]);//第10个元素的空间大小。 e=1;

f = sizeof(&arr);//sizeof把它当做地址来算的,4个字节 f=4;

g = sizeof(&arr[10]);//和上面同理 g=4;
    h=sizeof(str);//求字符串长度时包括最后的"\0",所以是6个字符    h=6;

printf("%d %d %d %d %d %d %d", a, b, d, e, f, g,h);

}

结果 a=1;b=4;d=10;e=1;f=4;g=4;h=6