What is function pointer?

M

Mike Wahler

sabarish said:
hi friend,

what is function pointer

A pointer object or value which contains the address
of a function.
how it is useful?

If one doesn't know what it is, not at all.

Now a question for you:
"What is a textbook, and how is it useful?"

-Mike
 
F

Flash Gordon

sabarish said:
hi friend,

what is function pointer how it is useful?
plz help me.

I suggest you just post the complete assignment together with your
instructors email address so we can send the answers direct.

Alternatively, at least attempt to find the answers in your text book.
 
O

osmium

sabarish said:
what is function pointer how it is useful?

It is a pointer that points to a function rather to a variable which is the
more common case.

A nice understandable usage is in the standard library, qsort which is geek
speak for quick sort. Think of three functions, main, qsort and compare.
main contains a pointer to compare which will tell qsort *how* to compare.
Comparing doubles is different that comparing ints, for example. so main
calls qsort and passes the pointer to compare (a function pointer) in the
argument list. This means that qsort can, in turn, use (call) the proper
compare function.
 
P

pete

sabarish said:
hi friend,

what is function pointer how it is useful?
plz help me.

The only thing that you can do with the name of a function
in a correct C program, is derive a pointer from it,
either through the address operator &, or by conversion.
 
M

Mike Wahler

pete said:
The only thing that you can do with the name of a function
in a correct C program, is derive a pointer from it,
either through the address operator &, or by conversion.

The *only* thing?

What about calling the function? :)

-Mike
 
B

Ben Pfaff

Mike Wahler said:
The *only* thing?

What about calling the function? :)

All function calls take place via function pointers. See the
standard:

6.5.2.2 Function calls
Constraints
1 The expression that denotes the called function77) shall have
type pointer to function returning void or returning an
object type other than an array type.

....

77) Most often, this is the result of converting an
identifier that is a function designator.
 
K

Keith Thompson

osmium said:
It is a pointer that points to a function rather to a variable which is the
more common case.

A nice understandable usage is in the standard library, qsort which is geek
speak for quick sort.
[snip]

Going off on a tangent ...

Quicksort is a specific recursive sorting algorithm. The name "qsort"
probably was originally an abbreviation for "quicksort" (back in the
days when some systems had severe limits on the lengths of external
names), but there's no implication in the standard that it uses any
particular algorithm.
 
K

Keith Thompson

Mike Wahler said:
The *only* thing?

What about calling the function? :)

The function call operator requires a function pointer. Given a
function name, you can't call the function without converting it to a
pointer, usually implicitly.
 
M

Mike Wahler

Ben Pfaff said:
All function calls take place via function pointers. See the
standard:

6.5.2.2 Function calls
Constraints
1 The expression that denotes the called function77) shall have
type pointer to function returning void or returning an
object type other than an array type.

...

77) Most often, this is the result of converting an
identifier that is a function designator.

I stand educated. Thanks.

-Mike
 

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

Forum statistics

Threads
474,294
Messages
2,571,518
Members
48,225
Latest member
JasminOrta

Latest Threads

Top