函數指標陣列
- 陣列宣告
typedef int (*pt2Function)(int, int) __reentrant; pt2Function funcArr1[10]; int (*funcArr2[10])(int, int) __reentrant; funcArr1 跟 funcArr2 宣告結果是一樣的,利用 typedef 比較容易理解。
- 範例程式
int Plus(int a, int b) __reentrant { return a+b; } int Minus(int a, int b) __reentrant { return a-b; } void main() { int (*funcArr[10])(int, int) __reentrant; printf("\nExecuting 'Array_Of_Function_Pointers'\n"); funcArr[0] = &Plus; funcArr[1] = &Minus; printf("12 + 5 = %d\n", funcArr[0](12, 5)); printf("12 - 5 = %d\n", (*funcArr[1])(12, 5)); }