Carbon is a tetravalent molecule. ie it has 4 electrons in the outer shell.
Its oxidation states are +4 and -4. By losing 4 electrons or by gaining 4 electrons , it will attain stable configuration Hence it can either lose or gain electrons during the formation of ionic bond. But carbon usually undergoes covalent bonding where electrons are shared.