When a star dies in the cosmos what happens depends upon what type of star it is and how large it is. When the core of a star completely runs out of hydrogen fuel, the star will naturally contract under the weight of gravity. There will be some hydrogen fusion that will take place in the upper layer as it contracts and heats up. They will expand first so they go just path of the Earth's orbit.
Then, they will fuse into carbon due to their helium levels. Then, when the helium fuel runs out, the main core will begin to expand and cool. The upper layers will then expand and then they will eject material. The material will collect all around the dying star and will form what is called a planetary nebula. Finally, the very core will cool into what is known as a white dwarf. Eventually, it will go into space as something called a black dwarf. It is an amazing process actually.