ITPub博客

首页 > > > 使用函数指针调用函数,加*与不加*的意义上有什么区别?

使用函数指针调用函数,加*与不加*的意义上有什么区别?

作者:chinarocky 时间:2019-09-03 11:39:08 0 删除 编辑
#include <iostream>

using namespace std;

char fun(char *str)
{
    return str[0];
}

void main()
{
    char *s = "one", a[5] = {0}, (*f1)(char *) = fun, ch = 'a';
    
    char ans = f1(&ch);
    cout << ans << endl;

    ans = (*f1)(s);
    cout << ans << endl;

    ans = f1(s);
    cout << ans << endl;

    cout << f1 << endl;
    cout << *(f1) << endl;
    /*
    输出结果:
    a
    o
    o
    001F1032
    001F1032
    */
}

从输出结果上来看,加*与不加*的结果是一样的.

总感觉写法不一样,意义上应该有不同,求解答!!!

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/4547/viewspace-3165622/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: npoi导出excel问题
请登录后发表评论 登录
全部评论

注册时间:2019-07-10

  • 博文量
    213
  • 访问量
    1691