1.sizeof的应用:
a). void *p = malloc(100);
sizeof(p)=4; 指针的字节数,不是要指针指向的内容。
b).void func(char str[100])
{ sizeof(str) = 4 ;} 数组作为函数参数时,被视为同类型的指针
c).char str[100];
sizeof(str) = 100; 不是函数参数时,为数组的大小
d). char str[] = "hello";
char *p = str;
int n = 10;
sizeof(str) = 6; sizeof(p)=4; sizeof(n) =2;
|
|
来自: audrey_guowei > 《我的图书馆》