Arrays of Functions

Arrays of Functions

A pointer to a function refers to the memory address of the function. Just like arrays, the name of a function is the starting address of the function’s code. Here’s a function prototype that recieves a pointer to a function as one of its parameters:

void update( employee [], int, void (*)() );

This indicates that “update” will recieve a function as an argument that is referenced by a pointer.

Suppose you have a couple of functions defined for manipulating some array of type employee: ComputeSalary, GiveRaise, Demote, Promote, etc. This would be the ideal call to the update function, assuming that the array of employees name is roll and the employee you wish to modify is indexed by being the fourth element of this array and you wish to ComputerSalary:

update( roll, 4, ComputeSalary );

If you wanted to Demote:

update( roll, 4, Demote );

Now, further suppose that you’ve got three functions: A, B, and C. Each returns void and takes one integer argument. To declare an array of pointers to these three functions:

void (*AoP[3])(int) = {A, B, C};

To call the nth element (or function) of AoP with argument Z:

(*AoP[n])(Z);
Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several

data fivetran pricing

Fivetran Pricing Explained

One of the biggest trends of the 21st century is the massive surge in analytics. Analytics is the process of utilizing data to drive future decision-making. With so much of