c/c++指针2

来源:互联网 发布:方媛moka的淘宝店 编辑:程序博客网 时间:2024/05/21 07:50
// test_finction_p1.cpp : Defines the entry point for the console application.
//typedef 定义可以简化函数指针的定义,在定义一个的时候感觉不出来,但是定义多了就知道方便了
#include "StdAfx.h"
#include <IOSTREAM.H>
#include <STRING>
using namespace std;
//定义一个简单的函数,只不过没有实现,也没有返回值,在java中叫做函数的申明 要想用这个函数,就只能实现了再说
int test(int a);
int main(int argc, char* argv[])
{
    cout<<test<<endl;
    typedef int(*fp)(int a);//注意,这里不是申明函数的指针,而是定义一个函数指针的类型,这个类型是自己定义的类型,类型名为fp,定义即申明了一块内存
    fp fpi;//这里利用自己定义的类型fp 定义了一个fpi的函数指针
    fpi=test;
cout<<"fpi(5)是:"<<fpi(5)<<"(*fpi)(10)是:"<<(*fpi)(10)<<endl;
cin.get();
    return 0;
}
int test(int a){
    return a-1;
}

// test_function_p.cpp : Defines the entry point for the console application.

0 0
原创粉丝点击