Heteroatoms, such as oxygen, nitrogen, sulfur, or halogens, replace hydrogen atoms in a hydrocarbon chain within functional groups. These heteroatoms introduce different chemical properties and reactivities into the molecule, contributing to the diversity of organic compounds.