gpt4 book ai didi

c - 如果是c中的指针,函数的大小返回什么

转载 作者:行者123 更新时间:2023-11-30 15:25:17 26 4
gpt4 key购买 nike

以下是我的代码

main(){

char a[2]={'a','b'};
copy_arr(a);
int i=1;
char *s=a;
printf("s=%d\n and",sizeof(s)/sizeof(*s));
printf("a=%d\n",sizeof(a)/sizeof(*a));
}

输出结果是s=4 且 a=2如果是指针,函数的大小返回什么。

最佳答案

sizeof(s)/sizeof(*s) 

这会返回

sizeof(pointer)/ sizeof(s[0]) /* Note that s[0] = *s */

4/1 ( I guess pointer is of size 4 on your system) = 4

另一个是

sizeof(a)/sizeof(*a)

sizeof(array)/sizeof(a[0])(2*1)/1 = 2

关于c - 如果是c中的指针,函数的大小返回什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27998853/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com