問題は、コードが何をするのか、関数が何をするのかを説明することです。
次のコードは、2年目の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;
}