gpt4 book ai didi

c - C中的数组求和,应该在(???)中插入什么来完成该功能?

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

int arraySum (int array[], int n)  
{
int sum = 0, *ptr;
for (ptr = array; ???; ++ptr)
sum += ???
return sum;
}
<小时/>

int n 是数组的大小。

最佳答案

因为这似乎是你的家庭作业/作业,所以我只给你两个提示,让它自己完成:

提示1:
当您有一个指向 int 的指针:int* ptr 时,您可以通过使用 dereference operator 取消引用您的指针来访问它指向的 int :*ptr

提示2:
当您将 ptr 增加 1 3 次时,它将指向与 ptr + 3 相同的内存。请注意,ptr + 3 指向地址&ptr[3] 处的内存。

关于c - C中的数组求和,应该在(???)中插入什么来完成该功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14954759/

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