I have a question about the allocation of memory in the
(2*k-1)-k+1) == k
((2*k-1)-k+1) == k
malloc() takes the argument for the number of bytes of memory to be allocated.
C11, chapter §126.96.36.199, The
void *malloc(size_t size);
mallocfunction allocates space for an object whose size is specified by
So, as long as
y evaluates to same value,
malloc(x * sizeof(sometype))
malloc(y * sizeof(sometype))
will give you pointers with same amount of memory to be accessed, provided the calls are success.
Finally, it's always better approach to not to use hardcoded values for the
sizeof operator, rather use the variable itself. Makes the code more robust, like
int *p = NULL; . . . p = malloc (x * sizeof(*p)); // type of `p` can change, // this statement need not be changed