關於指針函數和函數指針,指針函數函數指針
// 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;
}