93. 함수 포인터를 멤버로 가진 구조체 배열
다음 C 프로그램의 실행 결과를 쓰시오.
1#include <stdio.h>23struct Op {4char sym;5int (*fn)(int, int);6};78int add(int a, int b) { return a + b; }9int sub(int a, int b) { return a - b; }10int mul(int a, int b) { return a * b; }11int mod(int a, int b) { return a % b; }1213struct Op *find(struct Op *list, int n, char c) {14for (int i = 0; i < n; i++) {15if (list[i].sym == c) return &list[i];16}17return NULL;18}1920int main() {21struct Op table[4] = {{'+', add}, {'-', sub}, {'*', mul}, {'%', mod}};22char plan[] = "*%-+";23int v = 9;24for (int i = 0; plan[i] != '\0'; i++) {25struct Op *op = find(table, 4, plan[i]);26v = op->fn(v, i + 4);27printf("%c %d\n", op->sym, v);28}29table[0].fn = table[2].fn;30printf("%d\n", table[0].fn(3, 4) + find(table, 4, '-')->fn(10, 4));31return 0;32}