The slide on the majority of fully/semi-automatic pistols is the upper part that reciprocates ("slides") with recoil during the gun's operating cycle. It serves as the bolt carrier group (BCG) and partly as the receiver, and generally houses the firing pin/striker, the extractor and frequently also the barrel, and provides a mounting platform for iron and optical sights.
Through the principles of short recoil or simple blowback operations, the slide is moved backwards with each shot by the energy of expanding gasses caused by the combusting propellant (often a nitrocellulose-based smokeless powder, very rarely black powder). Because the slide is spring-loaded, once at the rearmost position, the spring tension will push it back towards the front. Generally, this slide movement cycle serves three functions: the extractor will empty the chamber by pulling out the spent casing from the previous shot (which then gets removed out of the gun by the ejector), the slide inertia will cock the hammer/striker to prepare for the next shot, and the bolt will push a new cartridge from the magazine into the chamber when the slide comes back forward. This action cycle will be repeated for continued firing as long as the magazine contains rounds and there is no failure to extract/eject (which causes stovepiping and double-feeding), failure to feed, or out-of-battery malfunction.
Fully/semi-automatic air pistols' slides operate with similar principles as firearms, except they utilize pneumatic energy from compressed gas (usually air, CO2, propane or refrigerants) instead of burning propellants. Because air pistols typically have much lower muzzle energy than firearms, there is less recoil that can be used to operate the slide. However, because airgun pellets/shots have no casings that needed to be extracted (unlike firearm cartridges), a very brief slide movement is sufficient to cycle the action and load the subsequent shot, so only a small amount of energy is needed to move the slide.
On most modern designs, once the magazine is empty, a slide stop will catch and lock the slide at its rearmost position, and will only be released to move back forward after the slide release is depressed.
Having the slide automatically loading the chamber and cocking the hammer/striker with each prior shot is essential for the function of double-action/single-action pistols. Hammerless and striker-fired pistols, lacking external hammer that can be directly manipulated, need to have the whole slide manually pulled back to cock the hammer/striker if the gun is not already cocked for firing.