How does a sniper rifle scope enables us to pinpoint the exact location even though the lens in situated 5-6 inches above the muzzle. The bullet leaves the muzzle and hits the target exactly where the cross-hairs in the scope pinpointed? How?
Look thru the sniper scope carefully, and you may see not just a simple crosshair, but several horizontal lines intersecting the vertical line. Each of those is for a different distance. At short distances, the error is from the scope and rifle barrel being offset from each other. At long distances, the gravitaional drop of the bullet is also taken into account.
Some scopes have a distance calibration setting instead of different lines for different distances. On those you dial in your distance, which angles the scope down appropriately to account for both the scope offset and the pre-computed bullet drop at that distance.
At really long distances, all sortf of subtle effects become significant. These include whether the rifle has been recently fired, which effects the temperature of the barrel, which can effect its straightness and how much of a gap there is between it and the bullet. A larger gap means more of the hot gasses escape without pushing the bullet. Wind and even air density are all considerations at long distances.
Bullets don't fly in straight lines. They fly in an arc, and often also veer sideways due to spin. Think how a pitcher throws a baseball. The fact that the scope is mounted above the barrel doesn't mean anything. Really, it could be mounted anywhere.
Here is a good article on Wikipedia about it: Rifleman's Rule
Picture says it all I think:
What happens when you mount a scope on a rifle is that it is calibrated. You take it to the firing range and mount the rifle in a fixed position and fire a shot at a known distance with a specific ammo type, and then adjust the scope mount to align the crosshairs. The other markings inside the scope take care of aim points for different distances, as others pointed out. Calibrating and re-calibrating the gun often is crucial. Even then, the shooter needs to adjust on the fly for various atmospheric factors and other circumstances (shooting downhill, uphill etc.)
So to answer your question about the "how": it's a combination of proper calibration, physics, and skill on part of the shooter.