çsizeof的字符指针 [英] C sizeof char pointer
本文介绍了çsizeof的字符指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么这个字符的最大变量等于1?
INT的main(){S1的char [] =你好;fprintf中(标准错误,(* S1):%I \\ N的sizeof(* S1))//打印出1}
解决方案
NOTA:这是为什么字符指针的大小1 的:原来的问题已经在一开始是改变了一点点p>
的sizeof(* S1)
是相同的
的sizeof(S1 [0])
这是一个字符
对象的大小和一个不大小字符
指针。
类型的对象的大小字符
总是 1
用C
要获得字符
指针使用的大小,这个前pression:的sizeof(安培; S1 [0])
Why is size of this char variable equal 1?
int main(){
char s1[] = "hello";
fprintf(stderr, "(*s1) : %i\n", sizeof(*s1) ) // prints out 1
}
解决方案
NOTA: the original question has changed a little bit at first it was: why is the size of this char pointer 1
sizeof(*s1)
is the same as
sizeof(s1[0])
which is the size of a char
object and not the size of a char
pointer.
The size of an object of type char
is always 1
in C.
To get the size of the char
pointer use this expression: sizeof (&s1[0])
这篇关于çsizeof的字符指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文