?
Solved

array of function pointers

Posted on 2012-08-13
3
Medium Priority
?
519 Views
Last Modified: 2012-08-13
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
0
Comment
Question by:nagaharikola
  • 2
3 Comments
 
LVL 36

Accepted Solution

by:
mccarl earned 2000 total points
ID: 38290633
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
 

Author Comment

by:nagaharikola
ID: 38290677
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
 
LVL 36

Expert Comment

by:mccarl
ID: 38290685
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.
Suggested Courses

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question