During the formation of a carbon dioxide molecule, the carbon atom shares four electrons with the oxygen atom on the left and four electrons with the oxygen atom on the right.
This means there will be eight electrons around each atom. Two pairs of electrons shared between two atoms make a double bond between the atoms, which is represented by a double dash.