#include "stdafx.h"
#include <iostream>
#include <string>
using namespace std;
// int dummy(int a[]) === int dummy(int* a)
int dummy(int a, int b) {
return a + b;
}
/*
int dummy2(int a[][]) {
// a[3][1] 报错, 有歧义,因为不知道参数a[][]是几行几列
a[3][1]
return 0;
// 所以可把参数改为 a[][6], 则说明每一行有6个元素
}
*/
#if 1
//函数指针
int main(void) {
int i;
int(*p)(int, int); //指向函数的指针
// dummy也是地址
p = dummy; // 也可以写成 int(*p)(int, int) = dummy;
i = p(3, 2);
cout << "value of i: " << i << endl;
cout << "addr of i: " << &i << endl;
cout << "addr of p: " << &p << endl;
cout << "*p: " << *p << endl;
cout << "value of p: " << p << endl;
cout << "value of dummy: " << dummy << endl;
// p相当于dummy函数的地址,放在代码区
//回调函数 callback function
//勾子函数 hook function
return 0;
}
#endif
5.4 指针及引用 【C++】
猜你喜欢
转载自blog.csdn.net/weixin_44773006/article/details/103534334
今日推荐
周排行