函数名之后不要留空格,紧跟左括号‘(’,以与关键字区别
函数 区别 关键字 之后 不要 空格 括号
2023-09-14 09:12:04 时间
函数名之后不要留空格,紧跟左括号‘(’,以与关键字区别。
1 #include <iostream> 2 3 /* run this program using the console pauser or add your own getch, system("pause") or input loop */ 4 using namespace std; 5 6 //参数为函数指针的函数 7 int get_result(int a, int b, int (*sub)(int,int)) 8 { 9 int r; 10 r=sub(a,b); 11 return r; 12 } 13 14 //计算最大值 15 int max(int a, int b) 16 { 17 cout<<"In max"<<endl; 18 return((a > b) ? a: b); 19 } 20 21 //计算最小值 22 int min(int a, int b) 23 { 24 cout<<"In min"<<endl; 25 return((a < b) ? a: b); 26 } 27 28 //求和 29 int sum(int a, int b) 30 { 31 cout<<"In sum"<<endl; 32 return(a+b); 33 } 34 35 36 int main(int argc, char** argv) { 37 int a,b,result; 38 39 //测试3次 40 for (int i=1;i<=3;i++) { 41 cout<<"Input a and b :"; 42 cin>>a>>b; 43 44 cout<<i<<"\tget_result("<<a<<","<<b<<", &max):"<<endl; 45 result =get_result(a, b, &max); 46 cout<<"Max of "<<a<<" and "<<b<<" is "<<result<<endl; 47 48 result = get_result(a, b, &min); 49 cout<<"Min of "<<a<<" and "<<b<<" is "<<result<<endl; 50 51 result = get_result(a, b, &sum); 52 cout<<"Sum of "<<a<<" and "<<b<<" is "<<result<<endl; 53 } 54 55 return 0; 56 }
相关文章
- PHP 暂停函数 sleep() 与 usleep() 的区别
- PHP判断变量是否存在及函数isset() 、empty()与is_null的区别
- php中empty(), is_null(), isset()函数区别
- lua调用dll导出的函数
- DoDataExchange函数,UpdateData(TRUE)和UpdateData(FALSE)的区别
- 【Teradata SQL】dayofyear与td_day_of_year函数区别
- Kotlin 朱涛 思维-1 函数式思维 命令式 声明式
- Python os模块——与操作系统相关的函数
- Python 批量抓取help()函数的帮助内容(附36M帮助文档)
- ORB-SLAM2 --- Frame::isInFrustum函数
- 模板方法(钩子函数)设计模式
- MySQL COUNT函数优化及count(1)/count(*)/count(列名)的区别
- Sql Server 常用函数
- c++模板学习06之类模板与函数模板区别
- 如何讲清楚函数防抖?
- Atitit 函数式编程与命令式编程的区别attilax总结 qbf
- C++:C++编程语言学习之实现约瑟夫环问题——利用函数嵌套+交互式实现n只猴子选猴王
- Qt 关闭应用程序和窗口的函数(quit(),exit()以及close()的区别)
- 函数之积的导数的图形解释
- 习题 8.19(1) 编写一个函数new,对n个字符开辟连续的存储空间,此函数应返回一个指针(地址),指向字符串开始的空间。new(n)表示分配n个字节的内存空间。
- Qt中通过信号槽函数获取发送信号的对象(qobject_cast、sender)
- Python: dict setdault函数与collections.defaultdict()的区别
- php中的正则函数:正则匹配,正则替换,正则分割 所有的操作都不会影响原来的字符串.
- Python标准库:内置函数object()
- LCC编译器的源程序分析(19)全局函数的定义
- C++中全局变量、函数与静态变量、函数的区别
- 函数重载和覆盖(重写)的区别
- sql中详解round(),floor(),ceiling()函数的用法和区别?
- 宏和函数的区别(一个BUG的总结)
- STM32-库函数学习之-指针函数和函数指针的区别
- MariaDB 存储过程与函数详解
- 前端进阶之---柯里化【函数式编程】
- C++基础知识要点--函数(Primer C++ 第五版 · 阅读笔记)
- maple中plot和plots函数的区别——笔记1
- python内置函数__init__及__str__的区别