fork(51) download
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. struct point
  6. {
  7. int x;
  8. int y;
  9. void (*print)(const struct point*);
  10. };
  11.  
  12. void print_x(const struct point* p)
  13. {
  14. printf("x=%d\n", p->x);
  15. }
  16.  
  17. void print_y(const struct point* p)
  18. {
  19. printf("y=%d\n", p->y);
  20. }
  21.  
  22. int main(void)
  23. {
  24. struct point p1 = { 2, 4, print_x };
  25. struct point p2 = { 7, 1, print_y };
  26.  
  27. p1.print(&p1);
  28.  
  29. p2.print(&p2);
  30.  
  31. return 0;
  32. }
  33.  
Success #stdin #stdout 0.02s 1676KB
stdin
Standard input is empty
stdout
x=2
y=1