When a hot water fixture opens, cold water flows into the heater. A gas burner or electric element heats water as it flows through the unit. Dual heat exchangers may preheat water for greater efficiency. The system adjusts flame or heating output to maintain a consistent temperature. The heated water exits the unit and supplies the open outlet. More @Wikipedia
Hover over any link to get a description of the article. Please note that search keywords are sometimes hidden within the full article and don't appear in the description or title.