Hydrocarbons can also be part of the exhaust gases.
In a 4-stroke gasoline engine, during valve overlap at top dead centre, some intake charge is drawn out of the combustion chamber into the exhaust port. Raw fuel, a mixture of hydrocarbons and air, is released into the atmosphere.
When combustion occurs in the cylinder, the walls, piston and piston rings are slightly cooler than points closer to the burning mixture. Some of the air and fuel molecules come in contact with these cooler parts, and they cool down, until their temperature becomes too low for combustion to occur. They are left unburned, and when the exhaust port opens, they leave the cylinder.
Misfiring of the ignition can result in unburned fuel leaving the cylinder when the exhaust port opens.
If an excessively rich air-fuel mixture is used, there is too much fuel for the quantity of air. Combustion will be incomplete, and any unburned fuel will leave the cylinder through the exhaust port.
If an excessively lean mixture is used, then combustion takes longer, and the flame may extinguish before it is complete. When the exhaust port opens, unburned hydrocarbons will be exhausted from the cylinder.