Not. You can only free() get the full block received from calling malloc() (or one of malloc() friends), and not part of that block.
Itβs best to leave the selected block as is and just use the pointer to the element in the index one, as if it were the beginning of the array (and ignore the last element).
Using memcpy works if it is really important to free two elements.
You can also move all elements from the left to one (i.e. move an element with an index of one to zero, etc.), and then call realloc() to resize the block and remove the last two elements. However, this is not a good idea, because the most likely result is that either (a) the main distribution of the heap will not actually change, and you will move and get profit, or (b) the basic distribution of the heap will be changed, and that's it will be moved a second time.
source share