1:用地址符 ampersand (&)来声明按地址"by reference"传递参数的方式只是在 C++中适用。在 C 语言中,我们必须用指针(pointers)来做相同的操作。
2:
参数的默认值(Default values in arguments)
当声明一个函数的时候我们可以给每一个参数指定一个默认值。如果当函数被调用时没
有给出该参数的值,那么这个默认值将被使用。指定参数默认值只需要在函数声明时把
一个数值赋给参数。如果函数被调用时没有数值传递给该参数,那么默认值将被使用。
但如果有指定的数值传递给参数,那么默认值将被指定的数值取代。例如:
// default values in functions 6#include <iostream.h> 5int divide (int a, int b=2) {
int r;
r=a/b;
return (r);
}
int main () {
cout << divide (12);
cout << endl;
cout << divide (20,4);
return 0;
}
我们可以看到在程序中有两次调用函数 divide。第一次调用: