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 - C Tutorial
From the course: Master C Language Pointers
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
(Locked)
Understanding pointers to pointers4m 32s
-
(Locked)
Sending a pointer to a function3m 36s
-
(Locked)
Sorting pointers2m 6s
-
(Locked)
Managing memory3m 56s
-
(Locked)
Creating pointers to functions2m 30s
-
(Locked)
Challenge: Manipulate a pointer array1m 18s
-
(Locked)
Solution: Manipulate a pointer array3m 20s
-
(Locked)