What are function pointers used for, and how would I use them?

前端 未结 9 2356
野趣味
野趣味 2020-11-29 06:51

I understand I can use pointers for functions.

Can someone explain why one would use them, and how? Short example code would be very helpful to me.

9条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-29 07:17

    For code, check out qrdl's response to state machines tutorials.

    I've used a variant of his method to implement a a menu for an LCD display I have on a board. Very very useful, makes the coding much cleaner and easier to read. Using function pointers makes expanding the number, names and ordering of menus very easy, and hides all those details from the higher level calling function that just sees 'hey, I write to the LCD here.'

提交回复
热议问题