C/C++ 언어 함수 포인터 인자를 사용하여 변환한 프로그램
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> void plus(int, int); void minus(int, int); void multiply(int, int); void result(void (*calculate)(int, int), int, int); int main(void) { int a=10, b=5; result(plus, a, b); result(minus, a, b); result(multiply, a, b); return 0; } void result(void (*calculate)(int a, int b), int x, int y) { /* calculate로 전달된 함수 실행 */ calculate(x, y); } void plus(int a, int b) { printf("%d + %d = %d\n", a, b, a+b); } void minus(int a, int b) { printf("%d - %d = %d\n", a, b, a-b); } void multiply(int a, int b) { printf("%d * %d = %d\n", a, b, a*b); } | cs |
C/C++ 언어 함수 포인터 인자를 사용하여 변환한 프로그램
'C,C++ > 예제' 카테고리의 다른 글
C/C++ 언어 함수 포인터 배열을 이용하여 두 정수의 합, 차, 곱을 구하는 예제 프로그램 (0) | 2016.06.14 |
---|---|
C/C++ 언어 함수 포인터의 인자에 대한 예제 프로그램 (0) | 2016.06.14 |
C/C++ 언어 구조체의 멤버 참조 이해를 위한 예제 프로그램 (0) | 2016.06.14 |
C/C++ 언어 offsetof 매크로에 대한 예제 프로그램 (0) | 2016.06.14 |
C/C++ 언어 중첩된 구조체의 초기화와 참조 방법에 대한 예제 프로그래 (0) | 2016.06.14 |