Ions are formed when atoms lose or gain electrons in order to fulfill the octet rule and have full outer valence electron shells. When they lose electrons, they become positively charged and are named cations. When they gain electrons, they are negatively charged and are named anions.
The answer is D. To put it simply, all atom wished to become stable. The only way for that is to obtain an octet structure where the outermost shell would have 8 electrons, thus being full.