Electroplating prevents the metal from being corroded. For ex when iron is coated with more reactive zinc metal zinc gets corroded and thereby preventing iron from corrosion.
The technique of protecting a metal from corrosion by connecting it to a second metal that is more easily oxidised is called Cathodic protection. It is not necessary to cover the entire surface of the metal with a second metal, as in galvanising iron; instead of, electrical contact with second metal is necessary. Underground steel pipeline is protected by connecting it through an insulated wire to a state of magnesium which acts as a sacrified anode and corrodes instead of iron. In this, easily oxidised Mg acts as anode, pipeline behaves as cathode, and moist soil is the electrolyte