问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
运行结果及报错内容
我的解答思路和尝试过的方法
我想要达到的结果
#include<iostream>
using namespace std;
int main()
{
const int n=5;
int a[n];
cout << &a;
void f(int* a, int n);
f(a, n);
return 0;
}
void f(int* a,int n)
{
int i = 0;int k=0; int m = 0;//m is tuichu,k is 1-3,i is xiabiao
for (i = 0; i < n; i++)
a[i] = i;
while (m < n-1)
{
if (*(a + i) != 0)
k++;
if (k == 3)
{
*(a + i) = 0; k = 0; m++;
}
if (i == n)i = 0;
i++;
}
cout << k << endl;
cout << *(a + i);
}