gpt4 book ai didi

c++ - 理解写得不好的代码,第二年 CS 过去的论文

转载 作者:可可西里 更新时间:2023-11-01 15:39:14 24 4
gpt4 key购买 nike

<分区>

题目是描述代码做什么,函数做什么。

以下代码是二年级 C 和 C++ 模块过去试卷的一部分。任务是描述以下代码的作用。我已经完全按照所提供的方式编写了代码,并添加了一些我自己的评论。

int g(int * y, unsigned size, int z) {
int tmp = y[0];
// what type is unsigned size? Int I presume. Why would you add an int to an array of ints?
int * b = y + size;
y[0] = z;
// I have the most difficulty understanding the following.
while (1) if (*(--b)==z){y[0] = tmp; return b - y;};
// are the following 3 lines ever even reached?
y[0] = tmp;
if (tmp == z) return 0;
else return -1;
}

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