Tag: function pointers

C Tutorial twelve on function pointers published

C Tutorial twelve on function pointers published

Lots of pointers
Image by pencil parker from Pixabay

While function pointers are important. I don’t think they’re quite as important as pointers. C would just not be C without pointers. There are so many things that you would not be able to do if the language lacked pointers. Things like most data structures (try doing a linked list without pointers!) .

However function pointers give additional flexibility. You can pass them as parameters in functions and store them in variables.

These are the earlier tutorials on pointers:

And this is the new one:

 

Function pointers in C and understanding them

Function pointers in C and understanding them

function pointers
Image by 준원 서 from Pixabay

In theory function pointers are straightforward. You have a pointer which is assigned to a function. You then make a call indirectly to that function. But, it’s when the function has parameters passed in and returns things that the definition  gets messy. Reading them is hard enough but trying to get it right when you are writing them can waste a lot of time.

Most days I read various websites and one of those is the C programming forum on reddit.com.  This has either articles or links to articles an one that was recently posted is about C function pointers and includes a very extensive list of definitions and what they mean with nearly 40 different examples of both legal and not legal examples. The examples are handy; just make sure you don’t use an illegal one. It won’t compile!