Advertisement
avr39-ripe

functionPointers

Mar 26th, 2020
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.75 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. void more() { std::cout << "More than ZERO!\n"; }
  4. void less() { std::cout << "Less than ZERO!\n"; }
  5. void zero() { std::cout << "ZERO!\n"; }
  6. void funVal(int val) { std::cout << "FunVal statred! val = " << val << '\n'; }
  7. void funVal1(int val) { std::cout << "FunVal1 statred! val = " << val << '\n'; }
  8. int max(int a, int b) { return a > b ? a : b; };
  9. int min(int a, int b) { return a < b ? a : b; };
  10.  
  11. int main()
  12. {
  13.     void(*numFun)() { nullptr };
  14.  
  15.     int num{};
  16.     std::cout << "Enter number: ";
  17.     std::cin >> num;
  18.  
  19.     //if (num == 0) { numFun = zero; };
  20.     if (num > 0) { numFun = more; };
  21.     if (num < 0) { numFun = less; };
  22.     if (numFun) { numFun(); }
  23.     else { std::cout << "numFun == nullptr!!!\n"; };
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement