求一数组程序解释(有个函数看不懂)
本帖最后由 discory 于 2013-01-11 14:39:34 编辑
#include <iostream>
using namespace std;
void someFunction( int [], int );
int main()
{
const int arraySize = 10;
int a[ arraySize ] = { 32, 27, 64, 18 ,95, 14, 90, 70, 60, 37 };
cout << "The values in the array are: " << endl;
someFunction( a, arraySize );
cout << endl;
system("pause");
return 0;
}
void someFuntion( int b[], int size )
{
if ( size > 0 )
{
someFunction( &b[1], size - 1 ); //这里看不懂, &b[1] ?
cout << b[0] << " ";
}
}
#include <iostream>
#include<string>
#include<vector>
#include<cstring>
using namespace std;
void someFunction(int[], int );
int main()
{
const int arraySize = 10;
int a[arraySize] = { 32, 27, 64, 18 ,95, 14, 90, 70, 60, 37 };
cout << "The values in the array are: " << endl;
someFunction(a,arraySize );
cout << endl;
system("pause");
return 0;
}
void someFunction(int *p,int size )
{
if ( size > 0 )
{
someFunction(p+1, size - 1 ); //这样你应该好理解吧,跟你的程序完全等价
cout << *p << " ";
}
}