Home
Archaeology
Astronomy
Biology
Books
Business
Chemistry
Coins
Computers
Conservation
Cooking
Earth Science
Farming
Economics
Finance
Games
Geography
Health Science
History by Date
Hobbies
Law
Mathematics
Medicine
Military Technology
Movies
Music
People
Pharmacology
Philosophy
Physics
Psychology
Religion
Science History
Technology
Sports
Television
Video
Visual Art
Privacy
Contact Us



Callback

In computer science, a callback is a concept, which allow a low level layer to call a function from a higher level layer, when usually, the higher level call the low level layer.

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 }

Example result

decimal:
15
16
17
18
19
hexa:
f
10
11
12
13
14

Copyright 2004. All rights reserved.