

Carbon has electroic configuration, 1s2, 2s2, 2p2. Thus it has 4 electrons in the outermost shell no. 2. So to attain a stable octet configuration it needs to have only four more electrons in its outershell. So it covalently shares these electrons with other atoms and achieves the required octet stability. Carbon atom has a electronegativity which lies in between the metals and the non-metals. That is, its electronegativity is not as low as for the metallic compounds because of which it cannot lose electrons completely, and it is also not as high as the non-metals, so it cannot gain all the electrons completely. Thus it can only shares electrons covalently.
