我正在尝试编写一个具有三个参数的递归函数;一个数组和两个数组索引。该函数应反转两个索引之间的值的顺序。我想了解正在发生的事情,而不是仅仅被告知答案。
到目前为止,这是我的代码:
#include <iostream>
using namespace std;
char switchAroo(char a[], int b1, int b2);
int main()
{
char a[6] {'A', 'B', 'C', 'D', 'E', '\0'};
cout << a;
switchAroo(a, 2, 5);
return 0;
}
char switchAroo(char a [], int b1, int b2)
{
char temp;
if (b1 == b2)
cout << "The array after switchAroo is " << a << endl;
else
{
temp = a[b1];
a[b1] = a[b2];
a[b2] = temp;
b1++;
b2--;
return switchAroo(a, b1, b2);
}
}
我收到以下警告代码:
warning C4715: 'switchAroo' : not all control paths return a value