-
如果没有const去修饰形参的话,那么形参的改变会影响实参; 如果用const去修饰形参的话,那么编译会报错,提示不能给a,b两个常量赋值查看全部
-
const 定义一个整形常量和#define定义的整形常量,效果是一样的,推荐使用const;查看全部
-
控制变量的const;查看全部
-
完全不会嘛!! #include <iostream> using namespace std; /** *函数功能:返回a和b的最大值 *a和b是两个整数 */ int getMax(int a, int b) { return a > b ? a : b; } /** * 函数功能:返回数组中的最大值 * arr:整型数组 * count:数组长度 * 该函数是对上面函数的重载 */ int getMax(int *arr,int count) { //定义一个变量并获取数组的第一个元素 int maxNum=arr[0]; for(int i = 1; i < count; i++) { //比较变量与下一个元素的大小 if(maxNum<arr[i]) { //如果数组中的元素比maxNum大,则获取数组中的值 maxNum=arr[i]; } } return maxNum; } int main(void) { //定义int数组并初始化 int numArr[3] = {3, 8, 6}; //自动调用int getMax(int a, int b) cout << getMax(numArr, 3) << endl; //自动调用返回数组中最大值的函数返回数组中的最大值 cout <<getMax(numArr[0],numArr[2])<< endl; return 0; }查看全部
-
#include<iostream> using namespace std; void fun(int i=30, int j=20,int k=10); void fun(double i,double j); int main(void) { fun(1.2,3.4); fun(100); fun(100,200); fun(1020,1200,3000); system("pause"); return 0; } void fun(int i) { cout << i << endl; } void fun(int i, int j,int k) { cout << i << " " << j << " " << k <<endl; } void fun(double i,double j) { cout << i << " " << j <<endl; }查看全部
-
#include<iostream> using namespace std; void fun(int i=30, int j=20,int k=10); int main(void) { fun(); fun(100); fun(100,200); fun(100,200,300); system("pause"); return 0; } void fun(int i, int j,int k) { cout << i << " " << j << " " << k <<endl; }查看全部
-
引用不能单独存在查看全部
-
总结: 函数参数的默认值 函数重载 内联函数查看全部
-
内联编译只是建议性的,具体操作还是有编译器决定; 逻辑简单,频繁调用的函数; 递归函数无法内联。查看全部
-
要用关键字inline定义内联函数查看全部
-
内联函数: 定义上与普通函数没什么区别 调用上:内联函数省略掉了②和④,即编译时,将实参和函数体中的代码,直接放到主程序中运行,而没有函数调用语句查看全部
-
重载的好处查看全部
-
函数重载:即函数名相同,但是函数的参数和个数不同查看全部
-
函数声明的时候可以有默认值,定义的时候不建议写,编译的时候可能不通过。 在没有实参的时候用默认值,否则实参覆盖默认值查看全部
-
函数参数可以有默认值!且,有默认值的参数必须写在参数表的最右端查看全部
举报
0/150
提交
取消