Do you use pointers to functions ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 6

Do you use pointers to functions ?

Are they useful or not ? I can't find a good usage for them. May be you can show a really needed example for them.

15th Jan 2017, 1:39 PM
abc
abc - avatar
15 Answers
+ 13
They are used for callback functions, which are defined by users of certain classes/API.
15th Jan 2017, 1:52 PM
Karl T.
Karl T. - avatar
+ 7
Also virtual functions are implemented with function pointers...that's how you get runtime polymorphism.
17th Jan 2017, 7:08 AM
Karl T.
Karl T. - avatar
+ 4
it's also used to save links in creating linked lists
16th Jan 2017, 2:37 PM
shazia fatima siddiqui
shazia fatima siddiqui - avatar
+ 4
Yes, but not a lot.
17th Jan 2017, 2:16 AM
Am²ar Yas²er
Am²ar Yas²er - avatar
+ 3
The first thing that comes to my mind as a very useful application is a button. Take the following code: int buttonID = CreateButton ("Click Me!", 100, 100, 200, 100, onClick); This would create a button at (100,100) with width 200 and height 100. Every time you click it, onClick is called. I use something similar in a personal Windows API wrapper. It makes creating buttons etc so much easier.
15th Jan 2017, 2:13 PM
Vishnu Sivan
Vishnu Sivan - avatar
+ 2
for a newbie like me, i used it for (easy to read) my own code.. because i want to differentiate some instructions into a function and i need the value from the function..
17th Jan 2017, 12:49 AM
yogaocean
yogaocean - avatar
+ 1
yes..it keeps the address of other function or variable
16th Jan 2017, 2:35 PM
shazia fatima siddiqui
shazia fatima siddiqui - avatar
+ 1
yes
16th Jan 2017, 2:52 PM
akhil hardy
akhil hardy - avatar
+ 1
it is just one of the concepts in c++.it is used just to enhance the efficiency of the program
16th Jan 2017, 4:33 PM
Raghavendra S P
Raghavendra S P - avatar
+ 1
It keeps the address of other variable or array
17th Jan 2017, 8:03 AM
Yash Saxena
Yash Saxena - avatar
+ 1
yes... they help us to point towards an address which is stored in a variable
17th Jan 2017, 10:49 AM
Rehan Suhaib
Rehan Suhaib - avatar
+ 1
pointers in functions are actually required in arrays as sometimes you cant actually pass the array to the function
1st Feb 2017, 4:21 PM
Prabal Titus
Prabal Titus - avatar
0
yes. the pointers to functions are useful to handle multiple functions with same return type
17th Jan 2017, 7:05 AM
Vishnu Sivan
Vishnu Sivan - avatar
0
yes
18th Jan 2017, 5:31 AM
Alan Josue
Alan Josue - avatar
0
pointer function is use to address a variable in the program
18th Jan 2017, 8:55 AM
Rahul