C Example
Here is an example in the C programming language
void counter( void (*cb)(int) ) { int i; for (i=15; i<20;i++) { cb(i); } }/** print number in hexadecimal */ void printHex(int i) { printf("%x\\n",i); }
/** print number in decimal */ void printDec(int i) { printf("%d\\n",i); }
int main(void) { void (*fn)(int); printf ("decimal:\\n") fn = &printDec; counter(fn); printf ("hexa:\\n") fn = &printHex; counter(fn);
return 0 }
decimal: 15 16 17 18 19 hexa: f 10 11 12 13 14