Carbon in hydrocarbons forms bonds by sharing of electrons.
Carbon forms four covalent bonds by sharing its four valence electrons with four univalent atoms, e.g., hydrogen. After the formation of four bonds, carbon attains the stable electronic configuration of 2,8.