The single argument to free()
is a pointer, passing a non-pointer will not compile, so the question is moot.
The effect of passing a pointer that was not previously returned from a heap allocation function and not previously passed to free()
is undefined - but never useful, or correct, and usually fatal.
In practice, free()
will assume the pointer is a block allocated from the heap; the implementation may detect the error, or it may corrupt the heap. The error may not be detected and will cause a failure undefined in nature at some later heap operation, making it very difficult to determine the original cause.
In a typical implementation allocated blocks are preceded by heap metadata; free()
accesses this data by subtracting the size of the metadata from the pointer passed to it. For a non-heap allocated pointer, the data read will be invalid nonsense. The implementation may be able to validate this data and cause a runtime error, but in a simple implementation, the metadata may contain just the size of the block, and a block of undefined size and inappropriate location may be added to the heap.