Explanation: Ionic compound is formed by the transfer of electron from one atom to another atom. When an electropositve atom lose an electron it form cation, whereas as anion is formed when an atom gain an electron. These actions and anions then attract each other and form an ionic compound. I hope it will help you.
Example: The formation of NaCl is best example of ionic compound. Na has one electron in its outer most shell which can easily be removed to form Na+, while Cl has seven electron in its outer most shell so it can easily gain an electron lost by Na to form Cl-. Then these ions attract each other and form NaCl as shown in the figure.