/*引用*/
/*输入10个整数,将其中最小的数与第一个数对换,把最大的数与最后一个数对换。
写3个函数...1...输入10个数..2..进行处理...3...输出10个数 */
#include <iostream> //预处理命令
using namespace std;
void deal(int& a[]); //函数声明
int main()
{
int b[10]; //定义变量
int i;
cout << "请输入10个整数:" <<endl; //输入
for (i = 0; i < 10; i++)
cin >> b[i];
cout << endl;
deal (b[10]); //处理,函数调用
cout << "下面是转换结果:" <<endl; //输出结果
for (i = 0; i < 10; i++)
cout << b[i] << " " ;
cout<<endl;
return 0;
}
void deal (int& a[10])
{
int j; //定义变量
int k;
int m;
for (j = 0; j < 9; j++) //最小放最前
if (a[j] > a[j+1])
j = j+1;
k = a[j];
a[j] = a[0];
a[0] = k;
for (j = 0; j < 9; j++) //最大放最后
if (a[j] < a[j+1])
j=j+1;
k = a[j];
a[j] = a[9];
a[9] = k;
}
--------------------Configuration: 003_2 - Win32 Debug--------------------
Compiling...
003_2.cpp
e:\neicole\study\c++\c++ (自学书本例题)\00_第06章习题\003_2.cpp(7) : error C2234: '<Unknown>' : arrays of references are illegal
e:\neicole\study\c++\c++ (自学书本例题)\00_第06章习题\003_2.cpp(18) : error C2664: 'deal' : cannot convert parameter 1 from 'int' to 'int *[]'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
e:\neicole\study\c++\c++ (自学书本例题)\00_第06章习题\003_2.cpp(29) : error C2234: '<Unknown>' : arrays of references are illegal
e:\neicole\study\c++\c++ (自学书本例题)\00_第06章习题\003_2.cpp(37) : error C2440: '=' : cannot convert from 'int *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
e:\neicole\study\c++\c++ (自学书本例题)\00_第06章习题\003_2.cpp(39) : error C2440: '=' : cannot convert from 'int' to 'int *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
e:\neicole\study\c++\c++ (自学书本例题)\00_第06章习题\003_2.cpp(44) : error C2440: '=' : cannot convert from 'int *' to 'int'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
e:\neicole\study\c++\c++ (自学书本例题)\00_第06章习题\003_2.cpp(46) : error C2440: '=' : cannot convert from 'int' to 'int *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
Error executing cl.exe.
003_2.obj - 7 error(s), 0 warning(s)
那引用可以直接引用数组?