How are stars formed? I read somewhere that when dust, gas, rocks etc come close to each other due to gravity, slowly and gradually build up a lot of pressure and form stars. If what I read is right, then from where did these materials come from?
It all starts in a molecular cloud, which are clouds in space with high densities. They can contain all kind of gases and dust and also due to their densities and relatively low temperatures they also contain molecules like H2, CO2 and H2O. These are in a thermodynamic equilibrium until something disturbs them (usually nearby supernovae). For some reason a zone of this cloud becomes denser and gravity wins to and starts to collapse the cloud until it forms a star.
These molecular clouds can be the remains of dead stars or simply a bunch of gas and dust collected and hold at the high-density zones at the galaxy's spiral arms or around the core.