C语言程序设计现代方法第十一章答案

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Chapter 11

Answers to Selected Exercises

2. [was #2] (e), (f), and (i) are legal. (a) is illegal because p is a pointer to an integer and i is an integer. (b) is illegal because *p is an integer and &i is a pointer to an integer. (c) is illegal because &p is a pointer to a pointer to an integer and q is a pointer to an integer. (d) is illegal for reasons similar to (c).

(g) is illegal because p is a pointer to an integer and *q is an integer. (h) is illegal because *p is an integer and q is a pointer to an integer.

4. [was #4; modified]

void swap(int *p, int *q)

{

int temp;

temp = *p;

*p = *q;

*q = temp;

}

6. [was #6]

void find_two_largest(int a[], int n, int *largest,

int *second_largest)

{

int i;

if (a[0] > a[1]) {

*largest = a[0];

*second_largest = a[1];

} else {

*largest = a[1];

*second_largest = a[0];

}

for (i = 2; i < n; i++)

if (a[i] > *largest) {

*second_largest = *largest;

*largest = a[i];

} else if (a[i] > *second_largest) *second_largest = a[i];

}

相关文档
最新文档