There is a well known pattern of figuring out array length:
int arr[10];
size_t len = sizeof(arr) / sizeof(arr[0]);
assert(len == 10);
T
The code is evil.
size_t known_len = 10;
int *ptr = malloc(known_len);
size_t size = known_len * sizeof(ptr[0]);
assert(size == known_len * sizeof(int));
The size of the memory allocation from your view point is 10 bytes. That is not 10 pointers to int.
known_len / sizeof(ptr[0])
will give you the number of integers that the allocation can hold.
As is, you are likely to go off the end of the allocation, leading to undefined behavior.
Consider malloc(known_length * sizeof ptr[0]);