什么是函数指针? [英] What is function pointer?

查看:89
本文介绍了什么是函数指针?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友,


什么是函数指针它是如何有用的?

请帮助我。

解决方案

sabarish写道:

什么是函数指针它是如何有用的?




搜索网页。 Google搜索C函数指针''即时显示

结果。


S.


" sabarish" <苏****** @ gmail.com>在消息中写道

news:11 ********************** @ z14g2000cwz.googlegr oups.com ...

嗨朋友,

什么是函数指针


指针对象或值包含地址

of a功能。

它有用吗?




如果一个人不知道它是什么,根本不知道。


现在问你一个问题:

什么是教科书,它有什么用?


- 迈克


" sabarish"写道:

什么是函数指针它是如何有用的?




这是一个指向函数的指针而不是一个变量是

更常见的情况。


一个很好理解的用法是在标准库中,qsort是极客

说快速排序。想想三个函数,main,qsort和compare。

main包含一个比较指针,它将告诉qsort *如何*进行比较。

比较双重比较不同于比较整数, 例如。所以main

调用qsort并将指针传递给

参数列表中的compare(一个函数指针)。这意味着qsort可以反过来使用(调用)正确的

比较函数。


hi friend,

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

解决方案

sabarish wrote:

what is function pointer how it is useful?



Search the web. A Google search for ''C "function pointer"'' gives instant
results.

S.


"sabarish" <su******@gmail.com> 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


"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.


这篇关于什么是函数指针?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆