can anybody telle me this

C

c beginner

i have a confusion about pointer to functions.can anybody help me to
overcome my confusion??
 
R

Richard Heathfield

c beginner said:
i have a confusion about pointer to functions.can anybody help me to
overcome my confusion??

What is it that is confusing you about pointers to functions?
 
S

Sachin

i have a confusion about pointer to functions.can anybody help me to
overcome my confusion??

function pointer holds address of function that you have specified.
as you call function by pointer.

fp = foo(int,int);
so you can call as
*fp(1,2);

depending on requrement you just assign address of function to
pointer.
it will get executed through function pointer call.
 
B

Barry Schwarz

function pointer holds address of function that you have specified.
as you call function by pointer.

fp = foo(int,int);
so you can call as
*fp(1,2);

Don't anyone take any of this code as legitimate c.
depending on requrement you just assign address of function to
pointer.
it will get executed through function pointer call.


Remove del for email
 
J

Joe Wright

Sachin said:
function pointer holds address of function that you have specified.
as you call function by pointer.

fp = foo(int,int);
so you can call as
*fp(1,2);

depending on requrement you just assign address of function to
pointer.
it will get executed through function pointer call.
Not quite like that. Let's define the function foo..

int foo(int a, int b) {
return a + b;
}

Now let's define a pointer to function returning int and taking two int
arguments.

int (*fp)(int, int);

Now initialize fp..

fp = foo;

Now you call it through the pointer with..

int x;
x = fp(1, 2);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top