Is Gibraltar part of the UK?

Not exactly. Gibraltar is a Crown Dependency, as is the Channel Islands and the Isle of Man. This means that they are able to pass their own laws and have their own currency but are still British sovereign territory so Britain is responsible for the defence of these places.