gpt4 book ai didi

c - 动态数组的大小

转载 作者:行者123 更新时间:2023-11-30 16:52:57 25 4
gpt4 key购买 nike

嗨,我想知道我的动态数组的大小

res=scanf(" %d%1s ",&x,c);
data[cnt++]=x;
if(x<0){
printf("Bad input1.\n");
return 0;
}
if(res != 2){
printf("Bad input2.\n");
return 0;
}
if(cnt >= size);{
size *=2;
data=(int*)realloc(data,size*sizeof(int));
}
}
printf("Length: %d\n",sizeof(data)/sizeof(int));
}

即使我扫描了 5 个以上的数字,它仍然告诉我尺码 4 或尺码 1 ...

最佳答案

您已经知道了缓冲区的大小。它正是size*sizeof(int)。 – 凯勒姆

关于c - 动态数组的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41080343/

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