C语言——小知识

来源:百度文库 编辑:神马文学网 时间:2024/05/23 15:31:50
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;