#include "stdio.h"
unsigned char
test(unsigned char c,unsigned char *d)
{
unsigned char size=sizeof(*d);
printf("---------\nsizeof for c = %d\n",sizeof(c));
printf("sizeof for *d = %d\n",sizeof(*d));
printf("sizeof for d = %d\n-------------",sizeof(d));
return size;
}
int main()
{
unsigned char a=0;
unsigned int b=0;
test(a,&a);
test(b,&b);
return 1;
}
输出:
---------
sizeof for c = 1
sizeof for *d = 1
sizeof for d = 4
----------------------
sizeof for c = 1
sizeof for *d = 1
sizeof for d = 4
-------------请按任意键继续. . .
说明:sizeof(指针)=4 ;存储地址的大小是固定的,与系统有关,这里一直是4。
而sizeof(*指针) 是指向地址的类型占用的大小。