455,426 Members | 1,757 Online
Need help? Post your question and get tips & solutions from a community of 455,426 IT Pros & Developers. It's quick & easy.

# What is function pointer?

 P: n/a hi friend, what is function pointer how it is useful? plz help me. Nov 15 '05 #1
10 Replies

 P: n/a sabarish wrote: what is function pointer how it is useful? Search the web. A Google search for 'C "function pointer"' gives instant results. S. Nov 15 '05 #2

 P: n/a "sabarish" wrote in message news:11**********************@z14g2000cwz.googlegr oups.com... 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 Nov 15 '05 #3

 P: n/a "sabarish" writes: 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. Nov 15 '05 #4

 P: n/a sabarish wrote: 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. -- pete Nov 15 '05 #5

 P: n/a "pete" wrote in message news:43***********@mindspring.com... sabarish wrote: 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. The *only* thing? What about calling the function? :-) -Mike Nov 15 '05 #6

 P: n/a sabarish wrote: 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. -- Flash Gordon Living in interesting times. Although my email address says spam, it is real and I read it. Nov 15 '05 #7

 P: n/a "osmium" writes: "sabarish" writes: 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. [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. -- Keith Thompson (The_Other_Keith) ks***@mib.org San Diego Supercomputer Center <*> We must do something. This is something. Therefore, we must do this. Nov 15 '05 #8

 P: n/a "Mike Wahler" writes: "pete" wrote in message news:43***********@mindspring.com... sabarish wrote: 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. 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. -- "For those who want to translate C to Pascal, it may be that a lobotomy serves your needs better." --M. Ambuhl "Here are the steps to create a C-to-Turbo-Pascal translator..." --H. Schildt Nov 15 '05 #9

 P: n/a "Mike Wahler" writes: "pete" wrote in message news:43***********@mindspring.com... sabarish wrote: 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. 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. -- Keith Thompson (The_Other_Keith) ks***@mib.org San Diego Supercomputer Center <*> We must do something. This is something. Therefore, we must do this. Nov 15 '05 #10

 P: n/a "Ben Pfaff" wrote in message news:87************@benpfaff.org... "Mike Wahler" writes: "pete" wrote in message news:43***********@mindspring.com... 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? :-) 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 Nov 15 '05 #11

### This discussion thread is closed

Replies have been disabled for this discussion.