#include
#include
#include
int main()
{
//指针与字符串
char a[]="helloworld";//定义一个字符数组,字符数组内容为helloworld\0
char *p=a;
printf("%s\n",p);
p="abcdef";//字符串常量存文字变量区,“”在使用时,取的是字符串常量首元素地址
//文字常量区内容不能改变
printf("%s\n",p);
printf("%d\n", sizeof(p));//8
printf("%d\n", sizeof("abcdef"));//7
printf("%d\n", strlen(p));//7
printf("%d\n", strlen("abcdef"));//6
return 0;
}
请问 printf("%d\n", sizeof(p));//8 这句语句执行结果为什么是8呢
p
是char*
类型指针,其大小等于架构字长,即在64位程序中是8个字节,在32位程序中是4个字节
因为p是指针类型,任何指针类型用sizeof计算的值都是8
因为指针本身其实是unsigned long类型