sizeof的的差异的char * x和焦炭点¯x之间[] [英] Difference of sizeof between char* x and char x[]
本文介绍了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*)
.
这篇关于sizeof的的差异的char * x和焦炭点¯x之间[]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文