Think of a pan of cooking sugar as made up of hundreds and thousands of molecules. Just like any other food, the molecules that make up sugar begin to break down under high heat or prolonged exposure to heat. Complex strings of molecules fall into their separate components. In this case, sucrose (simple table sugar) breaks down into glucose and fructose. If cooked long enough, these smaller molecules recombine into new molecules.
Each of these molecules, whether simple glucose or the more complex diacetyl, has their own distinct flavor and aroma. These flavors and aromas range from the general sweetness of raw table sugar to the buttery and floral notes of caramel to the final bitterness of burnt caramel.
Of course, all the molecules in a pan of cooking sugar don't all break apart and recombine at the same moment or even in the same manner! At first, only a few molecules here and there will break apart. Then more and more as the temperature of the sugar rises. A few will recombine, followed by the rest as cooking continues. This is how you can have both sweet and bitter notes at the same time.
The structure of the final sugar also changes as the sugar cooks. Cook briefly and you'll get a simple sugar syrup. Cooked a little more and you'll get a gooey, sticky sap. Cooked until almost all the molecules have recombined and you'll end up with a hard, brittle candy.
At any point in this process, we can stop the cooking and have a completely different flavor, color, and final texture. The majority of candy-making is knowing when to stop cooking just when the sugar has reached the exact balance of these components that you want in your final candy. This is where your skill and creativity come into play!