最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

函數(shù)指針學(xué)習(xí)1.3|函數(shù)指針作為函數(shù)參數(shù)

2022-01-03 22:34 作者:LogByMax  | 我要投稿


#include <iostream>

#include <vector>

using namespace std;

int test(int a)

{

? ? cout << "i am here in func_test\n";

? ? return a-1;

}

int test2(int (*fun)(int),int b)//第一個參數(shù) 是一個 指向返回值為int、函數(shù)參數(shù)為int的 函數(shù)指針,這里的指針名為fun。

{

? ? cout << "i am here in func_test2\n";

? ? int c = fun(10)+b;

? ? return c;

}

?

int main(int argc, const char * argv[])

{

? ??

? ? typedef int (*fp)(int a);//定義一個指向 返回值為int、函數(shù)參數(shù)為int的 函數(shù)指針

? ? fp f = test;

? ? cout<<test2(f, 1)<<endl; // 調(diào)用 test2 的時候,把test函數(shù)的地址作為參數(shù)傳遞給了 test2

? ? return 0;

}


輸出結(jié)果:

i am here in func_test2

i am here in func_test

10


函數(shù)指針學(xué)習(xí)1.3|函數(shù)指針作為函數(shù)參數(shù)的評論 (共 條)

分享到微博請遵守國家法律
平山县| 宁安市| 塘沽区| 安丘市| 贺州市| 晋江市| 达拉特旗| 财经| 城固县| 黑龙江省| 栾城县| 巴楚县| 曲松县| 黄石市| 常熟市| 图木舒克市| 周至县| 涞源县| 开鲁县| 呼图壁县| 精河县| 建宁县| 石楼县| 涞源县| 昭苏县| 浠水县| 西充县| 峨眉山市| 周宁县| 恩施市| 鹤庆县| 平潭县| 广州市| 望江县| 左权县| 中江县| 孝感市| 信阳市| 香河县| 资溪县| 六枝特区|