Advertisement
informaticage

Function pointer example

Mar 27th, 2021
634
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.26 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int square(int a) { return a * a; }
  4. typedef int (*square_fp)(int);
  5.  
  6. typedef struct {
  7.   int x;
  8.   square_fp fp;
  9. } data;
  10.  
  11. int main(void) {
  12.   data test;
  13.   test.x = 40;
  14.   test.fp = square;
  15.   printf("%d", test.fp(test.x));
  16.   return 0;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement