函数指针和变量指针之间的差异 [英] The different between function pointer and variable pointer

查看:112
本文介绍了函数指针和变量指针之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好



请告诉我

函数指针和变量指针之间的差异

<非常感谢
非常感谢



我的尝试:



函数指针和变量指针之间的差异

Hi all

Please tell me about
the different between function pointer and variable pointer

Many thanks

What I have tried:

The different between function pointer and variable pointer

推荐答案

区别在于指针的类型。它们都是指针,这意味着内存中的地址。



不匹配或误用指针会导致崩溃,所以我坚持使用键入指针并做好记录类型广告。



这里有一些关于指针的教程第15章到第18章。



了解这些问题是C程序员的基本技能。真的; - )
The difference is the "type" of the pointer. Both of them are pointers, that means the are addresses in the memory.

Mismatching or misusing pointers will lead to crashes, so I stick to typed pointers and do well documented type cast.

Here is some tutorial about pointers in the chapters 15 to 18.

It is a fundamental skill of a C programmer to understand these problems. Really ;-)


函数指针保存函数的地址。变量指针保存变量的地址。通常,您使用函数指针调用函数和指向变量的指针来访问变量的内容。例如

A function pointer holds the address of a function. A variable pointer holds the address of a variable. Typically you use a function pointer to call a function and a pointer to variable to access the variable's content. E.g.
#include <stdio.h>
int square(int x){return x*x;}
int main()
{
  float f = .5f;

  int (*fun)(int) = square; // 'fun' is pointer to function

  float * p = &f; // 'p' is pointer to variable

  *p /= 2;

  printf("%d %f\n", fun(2), f);


 return 0;
}


这篇关于函数指针和变量指针之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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