In C / C ++, in order to process an array, you need to know its size. Accordingly, one should always “remember” this size and drag it into all processing functions as an argument. For example:
void foo(int* arr, size_t n) { for (size_t i = 0; i < n; i++) { arr[i] = i * i; } } But when releasing resources, knowing the size for some reason is not necessary. You can simply call free(arr) if memory is allocated through malloc() or calloc() . Or you can use the delete[] arr; operator delete[] arr; if memory is allocated through the operator new int[n] .
The question is where does C / C ++ know how much memory should be freed if it does not know the size of the array? The free() function and the operator delete[] do not take as an argument the size of the array, but only a pointer to the array. And if C / C ++ can somehow calculate the size, then why is it constantly “dragging” with it in a separate variable?