Answer
While forming some compounds, atoms gain or lose electrons, and form electrically charged particles called ions. Compounds that are formed by the attraction of cations and anions are called as ionic compounds.
Ex : 2Na + Cl2 → 2Na+ Cl- → 2NaCl (sodium chloride- common salt.)
Sodium is a group 1 metal, thus forms a +1 charged cation. Chlorine is a non-metal, and has the ability to form a - 1 charged anion.
Compounds formed due to bonding of uncharged ions are called as molecular compounds and the bonding between them is called covalent bonding. Molecular compounds are formed by sharing of electrons between the two atoms and the elements are held together by covalent bonds.
Ex: 2C + O2 → 2CO ( Carbon monoxide)