Newbie C question. I have dynamic int array "n" inside my "Array" struct, I created an instance "arr" of "Array", after some manipulations with custom write functions (not sure if they are right though) I want to delete "n".
int main() {
Array arr = init_arr(5);
for (int i = 0; i < arr.length; i++) {
arr.n[i] = i;
}
print_arr(arr); // prints 0 1 2 3 4
add_to_arr(&arr, 228);
print_arr(arr); // prints 0 1 2 3 4 228
remove_from_arr(&arr, 0);
print_arr(arr); // prints 1 2 3 4 228
free_arr(arr);
// ? free_arr_IDK(&arr.n);
// ? free(arr.n); // even with this function it wont delete
print_arr(arr); // ??? prints 1 2 3 4 228
}
but after deleting an array and printing "arr.n", instead of mess of digits, it prints my array exactly as it was before calling free(). Output:
Array size: 5 {0 1 2 3 4 }
-- added <228> to end of array
Array size: 6 {0 1 2 3 4 228 }
-- removed element #0
Array size: 5 {1 2 3 4 228 }
Array size: 5 {1 2 3 4 228 }
Press any key to continue.
1. Is this behaviour expected? 2. If it's okay, which of functions really deletes "arr.n"? free_arr(arr) or free_arr(&arr)?