sizeof的的差异的char * x和焦炭点¯x之间[]
问题描述:
我知道的char *和char []之间存在差异。字符X [] =XXXX
是字符数组;的char * Y =XXXX
是一个指向文字(常量)的字符串;
和 X [4] =='\\ 0'
和 *(Y + 4)=='\\ 0'
太。
那么,为什么的sizeof(X)== 5
和的sizeof(Y)== 4
?
I know some difference between char* and char[].
char x[] = "xxxx"
Is an array of chars;
char *y = "xxxx"
is a pointer to the literal (const) string;
And x[4]=='\0'
, and *(y+4) == '\0'
too.
So why sizeof(x)==5
and sizeof(y)==4
?
答
sizeof运算数组类型是数组占用的大小。同的sizeof(XXXX)
。
The sizeof an array type is the size the array takes up. Same as sizeof("xxxx")
.
sizeof运算指针类型是指针本身占用的大小。同的sizeof(字符*)
。
The sizeof a pointer type is the size the pointer itself takes up. Same as sizeof(char*)
.