fork download
  1. #include <iostream>
  2.  
  3.  
  4. const double * f1(const double ar[], int n);
  5. const double * f2(const double [], int);
  6. const double * f3(const double *, int);
  7.  
  8. int main()
  9. {
  10. using namespace std;
  11.  
  12. double av[3] = {1112.3, 1542.6, 2227.9};
  13. const double* (*p1)(const double *, int) = f1;
  14. auto p2 = f2;
  15.  
  16. cout << "Using pointers to functions:\n";
  17. cout << "Address Value\n";
  18. cout << (*p1)(av, 3) << ": " << *(*p1)(av, 3) << endl;
  19. cout << p2(av, 3) << ": " << *p2(av, 3) << endl;
  20. const double* (*pa[3])(const double*, int) = {f1, f2, f3};
  21. auto pb = pa;
  22.  
  23. return 0;
  24. }
  25.  
  26. const double * f1(const double * ar, int n)
  27. {
  28. return ar;
  29. }
  30. const double * f2(const double ar[], int n)
  31. {
  32. return ar+1;
  33. }
  34. const double * f3(const double ar[], int n)
  35. {
  36. return ar+2;
  37. }
Success #stdin #stdout 0s 16048KB
stdin
Standard input is empty
stdout
Using pointers to functions:
Address Value
0x7fffc1cb73f0: 1112.3
0x7fffc1cb73f8: 1542.6