int a[10] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
for (int i = 0; i <= 9; i++) {
int tmp = a[i];
a[i] = a[9 - i];
a[9 - i] = tmp;
}
for (int i = 0; i <= 9; i++) {
printf("%d", a[i]);
}
Run Code Online (Sandbox Code Playgroud)
它的结果是:1234567890,但为什么不是10987654321,因为它在第一个for循环中切换值,但为什么在下一个for循环运行时不能更改它
我尝试将“int tmp”移到循环之外,但根本没有用。