冒泡里遍历比较会用到,两种都可以,不过要注意范围。容易混淆。

#include <iostream>

using namespace std;

int main() {
int a[3] = {0, 1, 2};

int i = 0, n = 3;

for(i = 0 ; i < n - 1; i++){
cout << a[i] <<" " << a[i+1]<< endl;
}

cout << "*****************************" << endl;

for(i = 1; i < n ; i++){
cout << a[i-1] << " " << a[i] << endl;
}
}