473,396 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

What is the use of Function Pointers in C language?

Hi friend,

what is the use of function pointer in c language and where it is
useful?
tell with simple example...?
plz help me.

Feb 21 '07 #1
26 25544
tn*******@gmail.com wrote:
Hi friend,

what is the use of function pointer in c language and where it is
useful?
tell with simple example...?
plz help me.
plz doesn't post here any more.

Functions pointers have many uses. They are used to implement generic
functions like qsort(), callbacks, state machines and anywhere else run
time binding of a function is required.

--
Ian Collins.
Feb 21 '07 #2
On Feb 20, 8:04 pm, tnowle...@gmail.com wrote:
Hi friend,

what is the use of function pointer in c language and where it is
useful?
tell with simple example...?
plz help me.

In sorting, we can pass a comparison function to a sort routine and
have a completely general sort for any data type. See:
http://www.hmug.org/man/3/qsort.php

Feb 21 '07 #3
On Feb 20, 8:19 pm, Ian Collins <ian-n...@hotmail.comwrote:
tnowle...@gmail.com wrote:
Hi friend,
what is the use of function pointer in c language and where it is
useful?
tell with simple example...?
plz help me.

plz doesn't post here any more.
How's he going to learn then?

Rather than hoping that posters go away, I hope that they will
improve. Sometimes they do.
Functions pointers have many uses. They are used to implement generic
functions like qsort(), callbacks, state machines and anywhere else run
time binding of a function is required.

--
Ian Collins.

Feb 21 '07 #4
user923005 wrote:
On Feb 20, 8:19 pm, Ian Collins <ian-n...@hotmail.comwrote:
>>tnowle...@gmail.com wrote:
>>>Hi friend,
>>>what is the use of function pointer in c language and where it is
useful?
tell with simple example...?
plz help me.

plz doesn't post here any more.

How's he going to learn then?

Rather than hoping that posters go away, I hope that they will
improve. Sometimes they do.
Read what I wrote again. I said the the mysterious 'plz' doesn't post
here any more, I didn't say anything to the OP about going away.

--
Ian Collins.
Feb 21 '07 #5
On Feb 21, 9:04 am, tnowle...@gmail.com wrote:
Hi friend,

what is the use of function pointer in c language and where it is
useful?
tell with simple example...?
plz help me.


Pointer to function is useful when you want to choose a
function dynamically at run time - usually based on certain
conditions.

To begin, check out the qsort fucntion in <stdlib.h>:

void
qsort(void *base, size_t nmemb, size_t size,
int (*compar)(const void *, const void *));

Here, you need to pass a pointer to the function that
compares the objects that you are sorting. Since qsort()
is a generic implementation and does not care what you
are sorting, it is up to you to implement a funtion
which compares the objects that you are sorting and
pass it on to qsort(). qsort() just invokes your
compare function by dereferencing the function
pointer.
Feb 21 '07 #6
Ian Collins <ia******@hotmail.comwrites:
user923005 wrote:
>On Feb 20, 8:19 pm, Ian Collins <ian-n...@hotmail.comwrote:
>>>tnowle...@gmail.com wrote:

Hi friend,

what is the use of function pointer in c language and where it is
useful?
tell with simple example...?
plz help me.

plz doesn't post here any more.

How's he going to learn then?

Rather than hoping that posters go away, I hope that they will
improve. Sometimes they do.
Read what I wrote again. I said the the mysterious 'plz' doesn't post
here any more, I didn't say anything to the OP about going away.
But if the OP doesn't know any better than to write "plz", he's likely
to miss the joke.

To the original poster: Please don't use silly abbreviations like
"plz", "u", "ur", and so forth. If you want us to take the time to
read what you've written, you need to take the time to spell out the
words. This is not a chat room.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 21 '07 #7
On Feb 21, 9:04 am, tnowle...@gmail.com wrote:
Hi friend,

what is the use of function pointer in c language and where it is
useful?
tell with simple example...?
plz help me.
this are good resource

www.function-pointer.org/
en.wikipedia.org/wiki/Function_pointer

--Raxit

Feb 21 '07 #8
Keith Thompson said:
Ian Collins <ia******@hotmail.comwrites:
>user923005 wrote:
>>On Feb 20, 8:19 pm, Ian Collins <ian-n...@hotmail.comwrote:
tnowle...@gmail.com wrote:
>plz help me.

plz doesn't post here any more.

How's he going to learn then?

Rather than hoping that posters go away, I hope that they will
improve. Sometimes they do.
Read what I wrote again. I said the the mysterious 'plz' doesn't
post here any more, I didn't say anything to the OP about going away.

But if the OP doesn't know any better than to write "plz", he's likely
to miss the joke.
If the OP doesn't know any better than to write "plz", he's unlikely to
be bright enough to learn C. (Yes, it *could* happen - it's just
unlikely.)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Feb 21 '07 #9
ra************@yahoo.co.in wrote, On 21/02/07 09:56:
On Feb 21, 9:04 am, tnowle...@gmail.com wrote:
>Hi friend,

what is the use of function pointer in c language and where it is
useful?
tell with simple example...?
plz help me.
this are good resource

www.function-pointer.org/
This paragraph is incorrect:
| Both, the executable compiled program code and the used variables, are
| put inside this memory. Thus a function in the program code is, like
| e.g. a character field, nothing else than an address. It is only
| important how you, or better your compiler/processor, interpret the
| memory a pointer points to.

I have developed in C for processors where program and address space
were completely different. On the implementation I am thinking of
unsigned int is large enough to represent and function or object
pointer, so on this implementation is is entirely possible you could
find "(unsigned int)func_ptr == (unsigned int)object_ptr" was true.

It also erroneously states, "Note: Although you may ommit the address
operator on most compilers you should always use the correct way in
order to write portable code" when in actual fact the standard allows
you to omit the & operator so on *any* conforming implementation you do
not need it.
en.wikipedia.org/wiki/Function_pointer
This isn't since the sentence "Function pointers are of the type the
function returns." is incorrect. Function pointers are of type pointer
to function (actually, they point to a function with with the specified
signature).
So over all, no, those are *not* good resources.
--
Flash Gordon
Feb 21 '07 #10
Richard Heathfield <rj*@see.sig.invalidwrites:
[...]
If the OP doesn't know any better than to write "plz", he's unlikely to
be bright enough to learn C. (Yes, it *could* happen - it's just
unlikely.)
I think that's likely to be unfair. There are contexts in which those
silly little abbreviations like "plz", "u", and "ur" are considered
appropriate (chat rooms, text messaging); given the awkwardness of
entering text on a mobile phone keypad, it's quite understandable.
And it's not entirely unreasonable (though it's wrong) to assume that
since Usenet is another computer-based discussion forum, the same
rules might apply.

Posting to a forum without first looking around to see what the
conventions are is a mistake, but most posters make that mistake only
once; there are just enough new posters showing up to make it look
like a continuous major influx. See
<http://en.wikipedia.org/wiki/Eternal_September>; thus today is
September 4922, 1993.

We have seen people learn and improve. They just need to remember
that using "plz" for "please" is bad, but using "char" for
"character", "{" for "begin", and "" for "function" are mandatory.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Feb 21 '07 #11
Keith Thompson said:
Richard Heathfield <rj*@see.sig.invalidwrites:
[...]
>If the OP doesn't know any better than to write "plz", he's unlikely
to be bright enough to learn C. (Yes, it *could* happen - it's just
unlikely.)

I think that's likely to be unfair. There are contexts in which those
silly little abbreviations like "plz", "u", and "ur" are considered
appropriate (chat rooms, text messaging);
By whom? In IRC, I will quickly /ignore anyone inconsiderate enough to
use such abbreviations. If I get a text message that I can't read, I
don't bother trying to decode it. I just delete it. If the sender later
asks whether I got their message, I reply (truthfully) that I got an
obviously corrupted message which I deleted unread.
given the awkwardness of
entering text on a mobile phone keypad, it's quite understandable.
If I can write English on mobile phone keypads, so can other
English-speaking people. It's hardly difficult.
And it's not entirely unreasonable (though it's wrong) to assume that
since Usenet is another computer-based discussion forum, the same
rules might apply.
The same rules DO apply!

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Feb 21 '07 #12
Richard Heathfield wrote:
Keith Thompson said:
Richard Heathfield <rj*@see.sig.invalidwrites:
[...]
If the OP doesn't know any better than to write "plz", he's unlikely
to be bright enough to learn C. (Yes, it *could* happen - it's just
unlikely.)
I think that's likely to be unfair. There are contexts in which those
silly little abbreviations like "plz", "u", and "ur" are considered
appropriate (chat rooms, text messaging);

By whom? In IRC, I will quickly /ignore anyone inconsiderate enough to
use such abbreviations. If I get a text message that I can't read, I
don't bother trying to decode it. I just delete it. If the sender later
asks whether I got their message, I reply (truthfully) that I got an
obviously corrupted message which I deleted unread.
given the awkwardness of
entering text on a mobile phone keypad, it's quite understandable.

If I can write English on mobile phone keypads, so can other
English-speaking people. It's hardly difficult.
If I do send text messages, (quite rare), I always take the time to
type the message in correct English. SMS-speak is horrible beyond
words. It's mainly acquired from folks who send a zillion text
messages a day, something that's abnormal in and of itself, and like
all habits, it quickly starts to stick to you.

Feb 22 '07 #13
On Feb 21, 10:16 pm, Richard Heathfield <r...@see.sig.invalidwrote:
Keith Thompson said:
Ian Collins <ian-n...@hotmail.comwrites:
user923005 wrote:
On Feb 20, 8:19 pm, Ian Collins <ian-n...@hotmail.comwrote:
tnowle...@gmail.com wrote:
plz help me.
>>>plz doesn't post here any more.
>How's he going to learn then?
>Rather than hoping that posters go away, I hope that they will
improve. Sometimes they do.
Read what I wrote again. I said the the mysterious 'plz' doesn't
post here any more, I didn't say anything to the OP about going away.
But if the OP doesn't know any better than to write "plz", he's likely
to miss the joke.

If the OP doesn't know any better than to write "plz", he's unlikely to
be bright enough to learn C. (Yes, it *could* happen - it's just
unlikely.)
That is really unfair. I mean, the whole point of writing a post is to
pass on a message. Some of us reading the message understands what
"plz" means, and provide some answers for it. Posting a comment which
is negative and personal like un-called for.

I wouldn't be surprise if "plz" becomes mainstream in a few
generations.

Tehn Yit Chin

Feb 22 '07 #14
te***********@gmail.com wrote:
On Feb 21, 10:16 pm, Richard Heathfield <r...@see.sig.invalidwrote:
<snip>
If the OP doesn't know any better than to write "plz", he's unlikely to
be bright enough to learn C. (Yes, it *could* happen - it's just
unlikely.)

That is really unfair. I mean, the whole point of writing a post is to
pass on a message. Some of us reading the message understands what
"plz" means, and provide some answers for it. Posting a comment which
is negative and personal like un-called for.
Apart from the aspersions cast on the OP's ability to learn C, (which
I agree was in bad taste), the main point of the thread stands: that
using silly abbreviations is inappropriate and counterproductive.
I wouldn't be surprise if "plz" becomes mainstream in a few
generations.
Curiously, this sort of mirrors the "standard vs. non-standard"
discussions that often take place here. The letter sequence 'plz' is a
non-standard but in some circles common form for the standard English
word 'please'. Using non-standard variants can potentially be
confusing because someone else might use 'pls' or 'pleaz' or 'pleas'
or 'plez' or 'ples' or another variant. Suddenly one well known and
well defined word has been burdened with innumerable poorly understood
and distasteful aliases.

Imagine the same happenning to most of the other commonly used words
and you begin to get the idea of the level of chaos that might result.

Though coining of new words is good, as is the development of a
programming language, in most cases it's better to stick to known and
accepted forms.

Feb 22 '07 #15
te***********@gmail.com wrote:
I wouldn't be surprise if "plz" becomes mainstream in a few
generations.

Tehn Yit Chin
Do you really, thnytch?

Richard
Feb 22 '07 #16
te***********@gmail.com said:
On Feb 21, 10:16 pm, Richard Heathfield <r...@see.sig.invalidwrote:
>Keith Thompson said:
But if the OP doesn't know any better than to write "plz", he's
likely to miss the joke.

If the OP doesn't know any better than to write "plz", he's unlikely
to be bright enough to learn C. (Yes, it *could* happen - it's just
unlikely.)

That is really unfair.
No, it isn't. It's common sense. Anyone asking other people for help in
C programming should be bright enough to realise that he will maximise
his chances of getting good quality help by minimising the time that
sometimes very busy people have to spend helping him. Writing his
message in some kind of obscure patois is therefore not a very
intelligent thing to do.
I mean, the whole point of writing a post is to pass on a message.
Yes, and the one to whom the communication is of some importance should
choose a communication form that will succeed in being understood
easily by the one to whom the communication isn't so important.
I wouldn't be surprise if "plz" becomes mainstream in a few
generations.
I wouldn't be surprised if wearing a ring through one's nose becomes
mainstream in a few years. That doesn't mean I'd choose to do it, or
find it attractive in those who do.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Feb 22 '07 #17
santosh said:
te***********@gmail.com wrote:
>On Feb 21, 10:16 pm, Richard Heathfield <r...@see.sig.invalidwrote:
<snip>
If the OP doesn't know any better than to write "plz", he's
unlikely to be bright enough to learn C. (Yes, it *could* happen -
it's just unlikely.)

That is really unfair. I mean, the whole point of writing a post is
to pass on a message. Some of us reading the message understands what
"plz" means, and provide some answers for it. Posting a comment which
is negative and personal like un-called for.

Apart from the aspersions cast on the OP's ability to learn C, (which
I agree was in bad taste),
I don't. I stand by my statement.
the main point of the thread stands: that
using silly abbreviations is inappropriate and counterproductive.
Right, and people who indulge in inappropriate, counterproductive
behaviour when supposedly learning a difficult technical subject are
less likely to succeed than those who do not.

<snip>

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Feb 22 '07 #18
Richard Heathfield wrote:
santosh said:
te***********@gmail.com wrote:
On Feb 21, 10:16 pm, Richard Heathfield <r...@see.sig.invalidwrote:
<snip>
If the OP doesn't know any better than to write "plz", he's
unlikely to be bright enough to learn C. (Yes, it *could* happen -
it's just unlikely.)

That is really unfair.
<snip>
Apart from the aspersions cast on the OP's ability to learn C, (which
I agree was in bad taste),

I don't. I stand by my statement.
the main point of the thread stands: that
using silly abbreviations is inappropriate and counterproductive.

Right, and people who indulge in inappropriate, counterproductive
behaviour when supposedly learning a difficult technical subject are
less likely to succeed than those who do not.
It's a bad habit and it's condoned in most chat rooms and web forums.
It doesn't follow that the concerned person lacks the intelligence to
learn a technical subject.

If the OP persists in using such aberrant words, even after being told
off, then he, (or she), is either truly rather dimwitted or is
malicious, with both of the said traits definitely not auguring well
for the OP's chances of successfully learning C.

Feb 22 '07 #19
te***********@gmail.com wrote:
>
.... snip ...
>
That is really unfair. I mean, the whole point of writing a post
is to pass on a message. ... snip ...

I wouldn't be surprise if "plz" becomes mainstream in a few
generations.
Exactly, and no. Failure to spell out the word fouls that message
and introduces unneeded ambiguity. Even if you only type at 60
wpm, the added time involved is 1/2 second. Even a hunt & pecker
can probably hit at least 15 wpm, or 2 full seconds.

You might as well recommend stuffing all ints into signed chars.
Same thing.

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Feb 22 '07 #20
In article <11**********************@a75g2000cwd.googlegroups .com>,
<te***********@gmail.comwrote:
>I wouldn't be surprise if "plz" becomes mainstream in a few
generations.
The idea that we'll still be pressing keys to send messages in a few
generations seems most implausible.

-- Richard

--
"Consideration shall be given to the need for as many as 32 characters
in some alphabets" - X3.4, 1963.
Feb 22 '07 #21
On Feb 22, 7:03 pm, r...@hoekstra-uitgeverij.nl (Richard Bos) wrote:
tehn.yit.c...@gmail.com wrote:
I wouldn't be surprise if "plz" becomes mainstream in a few
generations.
Tehn Yit Chin

Do you really, thnytch?

Richard
Why not, the alphabet could have lost its letters, mostly its vowels,
and the "art" of using spaces to delimit words is lost, so my name
would become "thnytch". Your name could become rchrdbs.

cheers,
thnytch
Feb 22 '07 #22
te***********@gmail.com said:
On Feb 22, 7:03 pm, r...@hoekstra-uitgeverij.nl (Richard Bos) wrote:
>tehn.yit.c...@gmail.com wrote:
I wouldn't be surprise if "plz" becomes mainstream in a few
generations.
Tehn Yit Chin

Do you really, thnytch?

Richard

Why not, the alphabet could have lost its letters, mostly its vowels,
and the "art" of using spaces to delimit words is lost, so my name
would become "thnytch". Your name could become rchrdbs.
whystptvwlspprcslttrsspcsndpncttnrclrlysprfls

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Feb 22 '07 #23
te***********@gmail.com wrote:
On Feb 22, 7:03 pm, r...@hoekstra-uitgeverij.nl (Richard Bos) wrote:
tehn.yit.c...@gmail.com wrote:
I wouldn't be surprise if "plz" becomes mainstream in a few
generations.
Tehn Yit Chin
Do you really, thnytch?

Richard

Why not, the alphabet could have lost its letters, mostly its vowels,
and the "art" of using spaces to delimit words is lost, so my name
would become "thnytch". Your name could become rchrdbs.
Yes, don't worry, it'll certainly happen at the End of days. Till then
let better sense prevail!

Feb 22 '07 #24
te***********@gmail.com wrote:
>
.... snip ...
>
Why not, the alphabet could have lost its letters, mostly its
vowels, and the "art" of using spaces to delimit words is lost, so
my name would become "thnytch". Your name could become rchrdbs.
You misspelled "thnytchn" :-)

Thin yeti chino. (May illustrate the problem)

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
Feb 23 '07 #25
te***********@gmail.com wrote:
On Feb 22, 7:03 pm, r...@hoekstra-uitgeverij.nl (Richard Bos) wrote:
tehn.yit.c...@gmail.com wrote:
I wouldn't be surprise if "plz" becomes mainstream in a few
generations.
Tehn Yit Chin
Do you really, thnytch?

Richard

Why not, the alphabet could have lost its letters, mostly its vowels,
and the "art" of using spaces to delimit words is lost, so my name
would become "thnytch". Your name could become rchrdbs.
Like hell it could.

Richard
Feb 23 '07 #26
On Feb 23, 12:26 pm, CBFalconer <cbfalco...@yahoo.comwrote:
tehn.yit.c...@gmail.com wrote:

... snip ...
Why not, the alphabet could have lost its letters, mostly its
vowels, and the "art" of using spaces to delimit words is lost, so
my name would become "thnytch". Your name could become rchrdbs.

You misspelled "thnytchn" :-)

Thin yeti chino. (May illustrate the problem)

--
Chuck F (cbfalconer at maineline dot net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net>
First time in a long while anyone has call me thin ;-)

Feb 23 '07 #27

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Peter Salzman | last post by:
Hi all, Since PHP is a (weakly) typed language, is it possible to overload functions based on the type of their argument? Also, are there function pointers in PHP? Here's why I'm asking. ...
2
by: Xiangliang Meng | last post by:
Hi, all. As far as I know, the speical arithmetic operator on void pointer is an externsion in GNU CC. However, I could not find the relative topics in C99. Would someone like to help me find...
7
by: Alfonso Morra | last post by:
How can this work ? I have the following declarations in a header: Header ========= typedef void (*VFPTR)(void) ; void FOO_Callback(void*, char*, char*, int, unsigned long, void*,void*);...
19
by: sabarish | last post by:
Hi friend, what is the use of function pointer in c language and where it is useful? tell with simple example...? plz help me.
18
by: ramu | last post by:
Can anyone tell me the advantages of using function pointers? Thanks in advance.
12
by: srinivas.satish | last post by:
Hi, is it possible to typecast a function pointer to two different prototypes. eg., typedef void (functptr1 *) (int , int); typedef void (functptr2 *) (int); functptr1 fptr; fptr =...
28
by: Peter Olcott | last post by:
I want to make a generic interface between a scripting language and native code, the native code and the interpreter will both be written in C++. The interpreter will probably be implemented as a...
3
by: googlinggoogler | last post by:
Hi This should all be pretty standard C stuff, but I'm going to use terms like mouse callback to communicate what Im tyring to do. Basically I have my program whirling around in an infinite...
8
by: a | last post by:
Hello. Suppose I have a family of functions f_0(x) = 0*x f_1(x) = 1*x .... f_n(x) = n*x taking float and returning float (naturally, the actual functions would
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.