From the course: Master C Language Pointers

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Creating pointers to functions

Creating pointers to functions - C Tutorial

From the course: Master C Language Pointers

Start my 1-month free trial

Creating pointers to functions

- [Man] Here's the man page definition for the qsort function. Yes, I know the text is tiny. But pay attention to the fourth argument. It's a function. The compar function evaluates individual items to be sorted. Yes, functions can serve as an argument to another function. But how does that work? Well, here is the prototype for a function as a variable. It's declared as a pointer. First comes the function's data type, void in this case. Then comes the function's name, like a variable name, as a pointer, enclosed in parentheses. Finally, come another set of parentheses with the function's arguments, or void for no arguments. Here's a typical C language program. It outputs an array of integers. The output function handles the job and it's called from within the main function here. Build and run, and there you go. This code is the same as the previous example with the same function output declared at line three. But within…

Contents