Let q amount of heat supplied to the system containing one mole gas in a cylinder fitted with a frictionless weightless moveable piston. At constant pressure, the gas molecules expand from volume V1 to V2, and the temperature changes from T1 to T2. According to the 1st law of thermodynamics, q = dU + w, where dU = change of internal energy. If the work is restricted to pressure volume work or mechanical work then w = PdV. Hence, q = dU + PdV.
Heat change in thermodynamics for ideal or real gases derived from the ist law of thermodynamics and ideal gas law or Van der Waals equation. All ideal and real gases obey these energy conservation formulas.