第一题:
知识点:
- 使用默认参数时要通过函数原型,因为编译器通过查看原型来获取函数信息;
- 使用引用作为函数形参,使用时直接将常规变量实参传入,函数会为该变量创建一个引用而非副本,所以准确的说算是一个伪指针,使用该伪指针直接对原始数据进行使用
#include <iostream>
#include <string>
using namespace std;
void show(const string &str,int i = 0);
static int counting = 0;
int main()
{
string str = "I'm in chaos";
show(str);
cout << endl;
show(str, 50);
cout << endl;
show(str, 15);
cout << endl;
show(str);
return 0;
}
void show(const string &str,int i)
{
counting++;
if(i != 0)
{
for(int j = 0; j < counting; j++)
cout << str << endl;
}
else
cout << str << endl;
}
第二题
知识点:
- 没有需要太注意的,主要就是告诉你大的变量用引用
#include <iostream>
using namespace std