程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> C++ >> C++入門知識 >> 關於指針函數和函數指針,指針函數函數指針

關於指針函數和函數指針,指針函數函數指針

編輯:C++入門知識

關於指針函數和函數指針,指針函數函數指針


// AllPointFunc1.cpp : 定義控制台應用程序的入口點。
//

#include "stdafx.h"
#include <iostream>
using namespace std;

//指針函數
int *func1(int i)
{
    return &i;
}
//和func1相同
int* func2(int i)
{
    return &i;
}

//指針函數
int *func3(int *i)
{
    return i;
}


//普通函數
int func4(int i)
{
    return ++i;
}

int main()
{
    int k = 3;
    cout << "\n=====\tfunc1\t=====" << endl;
    cout << "func1(k) : " << func1(k)<< "\n*func1(k) : " << *func1(k) << endl;
    cout << "\n=====\tfunc2\t=====" << endl;
    cout << "func2(k) : " << func2(k) << "\n*func2(k) : " << *func2(k) << endl;
    cout << "\n=====\tfunc3\t=====" << endl;
    cout << "func3(k) : " << func3(&k) << "\n*func(3) : " << *func3(&k) << endl;
    cout << "\n=====\tfunc4\t=====" << endl;
    cout << "(*func4)(k) : " << (*func4)(k) <<"\nfunc4(k) : " << func4(k) << endl;

    //函數指針
    int(*Pfunc4)(int);
    Pfunc4 = &func4;
    cout << "\n=====\tPfunc\t=====" << endl;
    cout << "(*Pfunc4)(k) : " << (*Pfunc4)(k) << "\nPfunc4(k) : " << Pfunc4(k) << endl;
    return 0;
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved