If you part exchange the car then they will deduct the outstanding finance and you will have the balance (if their is any) - If you sell the car privately then you will have to settle the balance
You are supposed to settle the outstanding debt BEFORE you sell the car but most people bend the rules a bit and usually pay it off from the proceeds of the sale.
If the buyer does his homework, the fact the car is on finance may well come to light.