This is especially true of rimfire guns (22 long rifle, 22 magnum, 17 HMR, etc), because when dry-fired the firing pin on such guns will often damage the rear surface of the barrel, against which the cartridge rim lies when the gun is loaded.
Dry firing can be a useful practice for becoming familiar with a gun, and many firearms training regimens call for it, but it must be done properly in order to ensure that the gun is not damaged in the process. This can usually be accomplished by use of "snap caps," which are dummy cartridges designed to cushion the blow of the hammer and/or firing pin.

