Compression of a gas increases its temperature, causing it to become hotter than its environment. If the gas is compressed adiabatically, there is no heat exchange with the surroundings, resulting in a temperature rise without heat loss. In contrast, isothermal compression requires the gas to be in contact with an external reservoir to maintain a constant temperature, allowing heat to flow out. The heat exchange depends on whether the compression is adiabatic or isothermal, not solely on the act of compression itself. Understanding these principles clarifies how work done on a gas affects heat flow.