To close the quickfix window, you use
:cclose, as @statox mentioned in the comments.
This won't affect which code buffer you're viewing, though. Vim doesn't distinguish between the buffer you were looking at originally and the buffers you navigated to via the quickfix, so to go back you are going to have to use Vim's regular buffer switching commands. If you know the name or number of the original buffer,
:b is probably quickest.
If not, you could try mashing Ctrl-O to jump backwards through the jumplist till you reach the right buffer, or you might want to set up some mappings* (or a plugin) for faster buffer navigation.
If you want something automated, how about adding something like following to your .vimrc?
nmap cX mAcX
nnoremap <leader>b :cclose<CR>`A
The first mapping changes the behaviour of
cX to first set up an uppercase mark
'A and then call the original mapping. Note that the original
cX mapping must already exist when this mapping is created, and that we use the recursive form
nmap rather than the usual
nnoremap in order that the original mapping will be invoked from our new one.
The second creates a new mapping that closes the quickfix and then returns to the marked position.
* Make sure you read as far down as the EDIT, because it's after that that the juicy details are included.