為結構體中函式指標賦值的兩種方法
阿新 • • 發佈:2019-01-07
/** 02. * 為結構體中的指標陣列賦值 03. */ 04. 05.#include <stdio.h> 06. 07.typedef struct test 08.{ 09. void (*p)(void); 10. void (*q)(void); 11. void (*y)(void); 12.}test; 13. 14.void f1(void) 15.{ 16. printf("f1\n"); 17.} 18. 19.void f2(void) 20.{ 21. printf("f2\n"); 22.} 23. 24.void f3(void) 25.{ 26. printf("f3\n"); 27.} 28. 29.int main(void) 30.{ 31. test aa = { 32. p : f1, //方法1 33. .q = f2, //方法2, 一般這種方式在全域性變數初始化的時候常用 34. }; 35. aa.y = f3; //方法3 36. 37. aa.p(); 38. aa.q(); 39. aa.y(); 40. 41. return 0; 42.}