函数嵌套(c++)
2013-12-06 11:56
127 查看
函数的嵌套是指在A函数里调用B函数(A,B都不是主函数)。当然,要注意的是:只允许函数的嵌套调用,但不允许函数的嵌套定义,也就是不能在A函数里定义B函数。 下面是函数嵌套作用一个简单的例子:求三个数中最大的一个。
本文出自 “Programming-is-an-Art” 博客,请务必保留此出处http://listentome.blog.51cto.com/7732963/1337405
#include<iostream> using namespace std; int maxoftow(int i,int j); //求两个数当中最大数 int maxofthree(int i,int j,int k); //求三个数当中最大数 int main() { int a,b,c; cout<<"please input three numbers:"<<endl; cin>>a>>b>>c; cout<<"The max of three numbers is:"<<endl; cout<<maxofthree(a,b,c)<<endl; return 0; } int maxoftow(int i,int j) { return (i>j?i:j); //满足条件返回 i,否则返回 j } int maxofthree(int i,int j,int k) { int max1,max2; max1=maxoftow(i,j); //在一个函数里面调用另外一个函数,函数嵌套 max2=maxoftow(max1,k); return max2; }
本文出自 “Programming-is-an-Art” 博客,请务必保留此出处http://listentome.blog.51cto.com/7732963/1337405
相关文章推荐
- c++沉思录笔记(21章代码)通过函数对象解决c++的函数嵌套问题
- c++中的函数嵌套调用和嵌套定义问题
- 函数嵌套(c++)
- C++学习笔记——异常处理匹配与函数嵌套
- 重新再学习C++的练习
- 终于把Carbide.c++ 1.2配置好了
- 官方水晶报表 .NET 应用程序实例下载 (C#、Visual C++.NET)
- Sams Teach Yourself C++ in One Hour a Day
- c/c++中运行外部程序
- C++思考题
- c++打印乘法表
- c++ python交互之boost.python 简集之Map处理
- C++之python函数调用
- string::npos 是什么 c++ /STL
- c++内存的分布
- 漫谈与c++相处的10个月
- 设计模式C++实现(2)——策略模式
- C++ 第十二周上机任务-输出“#”
- c++中的复制构造函数
- [C++]逐行读取文件与分割字符串方法