fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int plus ( int a, int b)
  5. {
  6. return a+b;
  7. }
  8.  
  9. int minus ( int a, int b)
  10. {
  11. return a-b;
  12. }
  13.  
  14. int m_max ( int a, int b)
  15. {
  16. if (a > b) return a;
  17. return b;
  18. }
  19.  
  20. int m_min ( int a, int b)
  21. {
  22. if (a < b) return a;
  23. return b;
  24. }
  25.  
  26.  
  27.  
  28. int main(int argc, const char *argv[])
  29. {
  30. void *arr[4] = {plus, minus, m_max, m_min};
  31. int a = 10, b = 5, c, d;
  32.  
  33. int(*yoba[])(int, int) = {m_min, m_max};
  34. printf ("m_min(%i %i) = %i \n",
  35. a, b, yoba[0](a,b) );
  36. printf ("m_max(%i %i) = %i \n",
  37. a, b, yoba[1](a,b) );
  38.  
  39.  
  40. c = ( (int(*)(int, int)) arr[0] )(a, b);
  41. d = ( (int(*)(int, int)) arr[1] )(a, b);
  42. printf ("%i + %i = %i\n", a, b, c);
  43. printf ("%i - %i = %i\n", a, b, d);
  44. return 0;
  45. }
Success #stdin #stdout 0s 1832KB
stdin
Standard input is empty
stdout
m_min(10 5) = 5 
m_max(10 5) = 10 
10 + 5 = 15
10 - 5 = 5