• C

array of function pointers

Hi,
can the function pointers  be passed to function as parameters.
how can we pass array of function pointers to functions as parameters

Thanks,
Hari
nagaharikolaAsked:
Who is Participating?
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
can the function pointers  be passed to function as parameters
Yes they can. If you have a function pointer such as...

int(*aFunction)(int arg1, char arg2);

Open in new window

That pointer could be passed to a function that is defined like this...

void doSomethingFunction(int aParam, int(*functionParam)(int arg1, char arg2) {
   // ...
   int returnValue = functionParam(69, 'E');
   // ...
}

Open in new window

how can we pass array of function pointers to functions as parameters
If you want to use arrays of function pointers, you just add the array syntax as normal, although this would probably look much better if you make use of typedefs, so...

typedef int (*pFunc)(int arg1, char arg2);

pFunc functionPointerArray[5];

// Fill array with function pointers to functions


// Function to accept function pointer array
void doSomethingElse(pFunc[] functionPointers) {
   // ...
}

Open in new window

0
 
nagaharikolaAuthor Commented:
hi mccarl,
your answer is clear to me.

If you have any reference for array of pointers it will be more useful


Thanks,
Hari
0
 
mccarlIT Business Systems Analyst / Software DeveloperCommented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.