Sugar used in cooking is sucrose. This is a disaccharide made from glucose and fructose
When sugar is heated, it firstly melts, then forms a syrup and boils
The molecules of sucrose break up with heat
As the sugar is heated, water leaves and evaporates in the oxygen and hydrogen. This causes the sugar to change from colourless to golden brown to dark brown to black. When it is black, it is carbon