The correct answer is:
A) When a star explodes as a supernova
Supernovae are powerful explosions that occur at the end of a star's life cycle, especially for massive stars. During a supernova, elements heavier than hydrogen and helium (such as carbon, oxygen, iron, and many others) are formed through nuclear fusion processes in the star's core and are then ejected into space. This process contributes to the spread of these heavier elements throughout the universe, enriching the interstellar medium from which new stars and planets can form.