Carbon forms compounds mainly by covalent bonding because carbon has small size, so neither it can loose four electrons easily, because very high amount of energy will be required, nor it can gain four electrons. Hence, it shares four electrons forming covalent bonds.