I have this function code to bubble sort an array using pointers.
However, I do not understand the second for loop (the inner one):
Why did they do p < a + n - i - 1?
void bubble_sort(int* a, int n) {
for (int i = 0; i < n; i++) {
for (int* p = a; p < a + n - i - 1; p++) { // bubble
if (*p > *(p+1)) {
int t = *p;
*p = *(p+1);
*(p+1) = t;
}
}
}
}