What is the use of function pointers? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the use of function pointers?

When to use function pointers

25th Jan 2019, 2:01 PM
Kewal Sharma
Kewal Sharma - avatar
7 Answers
+ 6
Another use for function pointers is setting up "listener" or "callback" functions that are invoked when a particular event happens. The function is called, and this notifies your code that something of interest has taken place. 
27th Jan 2019, 2:55 AM
Dan Rhamba
Dan Rhamba - avatar
+ 4
The most common use is to pass a function pointer to another function as a callback function.
26th Jan 2019, 4:42 AM
Ben Allen (Njinx)
Ben Allen (Njinx) - avatar
+ 2
Another use is that it can save time. If you use a function attached to an object or a module frequently, you can store it's reference in a variable for reuse. Import somemodule Name = somemodule.alligator.blender.trex.bee.themeaningoflife.generate.name() Print(Name())
27th Jan 2019, 12:14 AM
Audax
Audax - avatar
+ 1
Another use of function pointer is implementing something like class in C code. you can declare a struct inside it use malloc to implent properties and use function pointer to implent methods
29th Jan 2019, 10:01 AM
esmaeel ensanimehr
esmaeel ensanimehr - avatar
+ 1
Function pointers can be useful when you want to create callback mechanism, and need to pass address of a function to another function. They can also be useful when you want to store an array of functions, to call dynamically for example. Callback routines appear to be the most common scenario put forth thus far.
28th Nov 2020, 7:55 AM
Zahid Hasan
Zahid Hasan - avatar
0
Pointers to functions, or function pointers, point to executable code for a function in memory.
26th Dec 2019, 5:16 PM
Ravishankara H P
Ravishankara H P - avatar