1.引用作为函数参数
#include <iostream>
using namespace std;
int main()
{
int a = 10;
int &b = a;
cout<<a<<endl;
cout<<b<<endl;
cout<<&a<<endl;
cout<<&b<<endl;
return 0;
}
include <iostream>
using namespace std;
int main()
{
void swap(int & ,int&);
int i =3,j = 5;
swap(i,j);
cout<<"i="<<i<<endl<<"j="<<j<<endl;
getchar();
return 0;
}
void swap(int &a,int &b)
{
int temp;
temp = a;
a =b;
b= temp;
}
结果:
参考:https://blog.csdn.net/u012841414/article/details/81592031
2.随机函数的运用
# include <iostream> // 该文件包含标准输入输出流cout和cin
using namespace std;
int main( )
{
int i;
for(i=0;i<10;i++)
cout<<rand()%300<<" ";
cout<<endl;
srand(2);
for(i=0;i<10;i++)
cout<<rand()%10<<" ";
cout<<endl;
srand(1);
for(i=0;i<10;i++)
cout<<rand()%50<<" ";
cout<<endl;
}
结果:
3.c++链表
参考:https://blog.csdn.net/slandarer/article/details/91863177