Carbon and oxygen can combine to form two gases.
When combustion of carbon is complete, i.e. in the presence of plenty of air, the product is mainly carbon dioxide (CO2). Sources of carbon include; coal, coke, charcoal.
When combustion of carbon is incomplete, i.e. there is a limited supply of air, only half as much oxygen adds to the carbon, and instead, you form carbon monoxide (CO). The relative amount of CO produced depends on the efficiency of combustion.