C - Pointers to Functions

From EdWiki

Revision as of 09:30, 23 June 2015 by Jshankar (Talk | contribs) (1 revision imported: EdWiki -- Emsys pages from Shukra)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Pointers to Functions

In C, a function itself is not a variable, but it is possible to define “pointers to functions”, which can be assigned, placed in arrays, passed to functions, returned by functions and so on.

int (*draw)(int, int);

Which says that draw is a pointer to a function that has two integer arguments and returns an int.

int LineDraw(int, int);
draw = LineDraw;
(*draw)(i, j);  // call the function through function pointer
int LineDraw(int x, int y)  	{  }