1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
using namespace std;
const int * fun1(int *,int);
const int * fun2(int *,int);
const int * fun1(int * x, int y){
for(int i = 0;i < 5; i++)
x[i] += y;
return x;
}
const int * fun2(int * x, int y){
for(int i = 0;i < 5; i++)
x[i] -= y;
return x;
}
int main(){
const int *(*ptr[2])(int *,int) = {fun1, fun2};
int ary[] = {1,2,3,4,5};
cout << "fun1 :" << endl;
for(int i = 0 ; i < 5 ; i++){
cout <<*(*ptr[0])(ary,1)<<",";
}
cout << "\nfun2 :" << endl;
for(int i = 0 ; i < 5 ; i++){ // I dont know why the output was reversed
cout <<*(*ptr[1])(ary,1)<<",";
}
return 0;
}
|