1.函数参数传递指针
2.函数返回指针
3.函数指针调用函数
4.函数指针作为参数
5.typedef使用
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void getValue(int * p_point){
*p_point = 100;
}
int *updateScore(int * score){
if(*score <60){
*score = 60;
}
return score;
}
int add(int a,int b){
return a+b;
}
int calc(int a,int b,int (*fun)(int ,int )){
return fun(a,b);
}
void updateName(string ** p_name){
*p_name = new string();
}
int main() {
int score = 30;
getValue(&score);
cout<< score << endl;
int score2 = 12;
int *up_score = updateScore(&score2);
cout << "修改后的分数="<< *up_score << endl;
string * p_name = nullptr;
updateName(&p_name);
*p_name = "小明";
delete p_name;
int (*fadd) (int,int)= add;
int result = fadd(1,3);
cout << "result="<< result<<endl;
int a = 10;
int b = 30;
cout << calc(a,b,add)<< endl;
typedef int myi;
myi age = 30;
typedef vector<int> vi;
vi nums = {1,2,3};
return 0;
}