C: 当字符数组首指针转化成char *指针,sizeof(*ptr)不为array的size

#include <stdio.h>
#include <string.h>

int main()
{
	char a[10] = "\0";

	char *pa = (char *)&a;
	char (*paa)[10] = &a;

	printf("-----a[10]----\n");
	printf("a size:%d, pa size;%d, *pa size:%d, *paa size:%d\n", sizeof(a), sizeof(pa), sizeof(*pa), sizeof(*paa));

	return 0;
}
#./aaa
-----a[10]----
a size:10, pa size;8, *pa size:1, *paa size:10

当字符数组的首地址,强制转化成char *指针后: sizeof(*ptr) 不为array的大小;

posted @ 2018-05-13 18:41  苏小北1024  阅读(298)  评论(0编辑  收藏  举报