Functions+in+variables

A quick hack to show the incredibly ugly syntax in C for putting pointers to functions in variables and arrays. code format="c"
 * 1) include 
 * 2) include 
 * 3) include 

squarem(int ix) { printf("squarem(%i) = %i", ix, ix*ix); } cubem(int ix) { printf("cubem(%i) = %i", ix, ix*ix*ix); } halfem(int ix) { printf("halfem(%i) = %i", ix, ix/2); }

int (*myFunc)(int);

main { squarem(6);         printf("\n"); cubem(6);           printf("\n"); halfem(6);          printf("\n"); myFunc = squarem;   printf("\n"); myFunc(8);          printf("\n");

makeFunkyTable; }

showIt(int ix){ printf("%i", ix); }

makeFunkyTable { int (*funcArray[4])(int); int fx, arg;

funcArray[0] = showIt; funcArray[1] = halfem; funcArray[2] = squarem; funcArray[3] = cubem;

for(arg=0; arg <= 10; arg++) { for(fx=0; fx<=3; fx++) { funcArray[fx](arg); printf("\t"); }   printf("\n"); } } code And the output: code func squarem(6) = 36 cubem(6) = 216 halfem(6) = 3

squarem(8) = 64 0   halfem(0) = 0    squarem(0) = 0    cubem(0) = 0 1   halfem(1) = 0    squarem(1) = 1    cubem(1) = 1 2   halfem(2) = 1    squarem(2) = 4    cubem(2) = 8 3   halfem(3) = 1    squarem(3) = 9    cubem(3) = 27 4   halfem(4) = 2    squarem(4) = 16    cubem(4) = 64 5   halfem(5) = 2    squarem(5) = 25    cubem(5) = 125 6   halfem(6) = 3    squarem(6) = 36    cubem(6) = 216 7   halfem(7) = 3    squarem(7) = 49    cubem(7) = 343 8   halfem(8) = 4    squarem(8) = 64    cubem(8) = 512 9   halfem(9) = 4    squarem(9) = 81    cubem(9) = 729 10   halfem(10) = 5    squarem(10) = 100    cubem(10) = 1000

code See also: @Hash examples