The factor that determines this is the atomic structure of these two elements which determines how many electrons are found on the outer shell or energy level of these elements.
Ability to form single, double or even multiple covalent bonds is directly dependent on the number of electrons on the outer energy level.
The atomic structure of oxygen 2:8:6 with the outer shell having 6 electrons. Oxygen readily accepts and share 2 more electrons from another element forming two covalent bonds.
Likewise carbon has an atomic structure of 2:4 with 4 electrons in the outer shell. It readily shares these electrons with other elements to form 4 covalent bonds with them.