#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
void insertion_sort(int arr[]);
void insertion_sort(int arr[]) {
int hold;
int key;
for (int i = 2; i < 7; i++) {
key = arr[i];
hold = i- 1;
while (hold >= 0 && arr[hold] > key) {
arr[hold + 1] = arr[hold];
hold--;
}
arr[hold + 1] = key;
}
}
int main() {
int arr[] = {3,4,5,6,7,1,4};
insertion_sort(arr);
for (int i = 0; i < sizeof(arr) / sizeof(int); i++) {
printf("%d", arr[i]);
}
return 0;
}
It seems like I cannot use [ sizeof(arr) / sizeof(int) ] in order to get the length of the array in insertion_sort. So I used the integer number instead. What is the reason and what's the proper way of manipulating the array that's taken as a parameter of a function??