çsizeof的字符指针 [英] C sizeof char pointer

查看:130
本文介绍了çsizeof的字符指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么这个字符的最大变量等于1?

  INT的main(){S1的char [] =你好;fprintf中(标准错误,(* S1):%I \\ N的sizeof(* S1))//打印出1}


解决方案

NOTA:这是为什么字符指针的大小1

的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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆