运行代码:
//数组练习
#include"std_lib_facilities.h"
int ga[10];
void f(int a[],int n)
{
int la[10];
for (int i = 0; i < 10; i++)
{
la[i] = ga[i];
cout << la[i] << " ";
}
cout << "\n";
int* p = new int[n];
for (int i = 0; i < n; i++)
{
p[i] = a[i];
cout << p[i]<<" ";
}
cout << "\n";
delete[]p;
}
int main()
try
{
for (int i = 0; i < 10; i++)
{
ga[i] = pow(2, i);
cout << ga[i] << " ";
}
cout << "\n";
f(ga, 10);
int aa[10];
for (int i = 0; i < 10; i++)
{
aa[i] = 1;
int j = i+1;
while (j > 1)
{
aa[i] *= j ;
j -= 1;
}
}
f(aa, 10);
return 0;
}
catch (exception& e) {
cerr << "error:" << e.what() << '\n';
keep_window_open();
return 1;
}
catch (...) {
cerr << "Oops:unknown exception!\n";
keep_window_open();
return 2;
}
运行结果: