int &counter是什么意识?为什么要用&。

#include
using namespace std;
void count(bool YN, int &counter);
void count(bool YN, int &counter)
{
if (YN)
{
counter++;
}
}
void main()
{
int counter = 0;
bool YN = 1;
while (YN)
{
count(YN, counter);
cout << counter << endl;
if (counter > 5)
{
YN = 0;
}
}
system("pause");
}

& 在变量前面,是引用的意思; 比如

int a = 10;
int &b = a;

b = 20;

//那么这个时候a的值也是20了

在你这个代码中使用引用传递参数的话,那在函数里面就可以改变实参的值,而且使用引用的好处就是可以提高性能

&是c++中的引用,我个人认为就是为那些指针没学好的特地设置的。
以下链接是关于c++的&的使用与说明
https://blog.csdn.net/qq_38386991/article/details/82719171

C++引用,相当于直接操作引用的对象~