Here's why:
* Magnesium (Mg) is an alkaline earth metal, readily forming ionic bonds with nonmetals.
* Carbon (C) can form multiple bonds, including the carbonate ion (CO₃²⁻) which has a -2 charge.
* Oxygen (O) is a highly electronegative element, readily forming ionic bonds with metals.
When magnesium reacts with carbon and oxygen, it forms the ionic compound magnesium carbonate. The magnesium ion (Mg²⁺) forms a strong electrostatic interaction with the carbonate ion (CO₃²⁻), resulting in a neutral compound.