sizeof 的一个疑惑
Recently i was reviewing the C,I found a problem during the process.
Poset code:
#include<stdio.h>
int main()
{
char a[10];
char *hello="hello welcome to my home";
printf("the hello is%d\n",sizeof(hello));
printf("the a is%d\n",sizeof(a));
}
Suprisely I get the Following Result:
the hello is4
the a is10
Expected someaone guide me ,Thanks very much!
sizeof C
[解决办法]
hello是一个指针,sizeof(指针)计算一个指针占用的空间大小,32位系统一般是4
sizeof(数组名),计算一个数组占用的空间,char a[10],那就是sizeof(char)*10 = 1*10 = 10
[解决办法]
指针的大小是保存一个地址所需的内存大小, 32 位系统 4 个字节. 数组的大小就是数组占用空间的大小.