function pointer array
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #include <stdio.h> int add (int, int); int subtraction (int, int); int multiple (int, int); int division (int, int); int main (void) { int funcNumber = 0; int number1 = 0, number2 = 0; int (*functionPointer[4]) (int, int); functionPointer[0] = add; functionPointer[1] = subtraction; functionPointer[2] = multiple; functionPointer[3] = division; printf("%d\n", functionPointer[2](10, 20)); return 0; } int add (int number1, int number2) { return number1 + number2; } int subtraction (int number1, int number2) { return number1 - number2; } int multiple (int number1, int number2) { return number1 * number2; } int division (int number1, int number2) { return number1 / number2; } | cs |
0 개의 댓글:
댓글 쓰기