That's called the Coriolis Effect. Beyond around 1000 yards it has to be taken into account, and the extent of the effect also depends on the direction you are firing. Ballistic computers do all those compensating aiming calculations. Back during WWII such computers existed aboard the ship but they were mechanical, not electronic, with lots of gears, screws, and cams. It was quite an art, and it took considerable skill, to operate them.
When they recommissioned the Iowa class BBs, the US Navy debated replacing the mechanical fire control computers because they worked really well and were very reliable.
The main additions in the 1980s refits were the switch to the more modern Mark 160 Fire Control System along with DR-810 radar in each turret to measure muzzle velocity of the outgoing rounds, along with better powder formulation using cooler burning diphenylamine based powder, a titanium dioxide and wax based additive, and polyurethane coated powder bags to reduce gas erosion of the barrels, increasing the life of the barrel liners from 290 rounds to around 1500 rounds.
The USN also remixed the powder used in the 1980s. When first produced in WWII, the powder produced shot to shot variation of less than +/- 10 ft per second, which increased to 14 fps in Korea, 23 fps in Vietnam and 32 ft per second in the early 1980s. The remixed powder again produced consistency of +/- 10 fps. This combination of fire control, powder and reduced bore erosion produced exceptional accuracy.
For example, in 1987, fifteen shells were fired in tests at 34,000 yards (19.32 miles). 14 out of the 15 landed within 250 yards (230 m) of the center of the target and 8 were within 150 yards. Shell-to-shell dispersion was 123 yards. That's not bad when shooting rounds that leave 50' diameter craters with blast effects that are several times that distance.
----
During WWII, the accuracy of US battleships in North Carolina, South Dakota and Iowa classes was due to a combination of two elements.
The electromechanical analog fire control computer (Ford Instrument Company Mark 8 Range Keeper) in the plotting room, where the trajectories were calculated, and the Mk 38 Ship Gun Fire-Control System (GFCS) located high in the ship where radar and range finder data were used to produce the data needed for tachymetric target motion prediction to compute the corrections needed to get the second round or salvo on target. There were three of the Mk 38 GFCS in the Iowa class BBs.
Against a fixed target on land at normal shore bombardment ranges, two shots is all it usually took. Against a maneuvering ship target it was a lot more challenging, but no ship class in any navy ever did it more effectively than an Iowa class BB.
It's a bit of an exaggeration to say an Iowa class BB could hit a VW Beetle at a range of 42,345 yards (24.05 miles) for the AP Mk 8, and 41,622 yards (23.65 miles) for the HC Mk 13, but given that the HC Mk 13 round would leave a crater 50' wide and 20' deep, with enough blast to knock down trees 400 yards away, a near miss was good enough to take out a VW Beetle.
In terms of actual hit percentages on ship targets, at 10,000 yards (5.68 miles) the hit percentage for a ship presenting a broadside target was around 33% (varying slightly depending on the spotting method used (visual, aircraft or radar) and about 22% for a bow on target. At 20,000 yards (11.36 miles) the hit percentages fell to 10.5% and 4.1% respectively and at 30,000 yards (17.04 miles) they were 2.7% and 1.4%.
Remember though that this is firing from a moving and maneuvering ship at another moving and maneuvering ship, each with speeds around 30 kts, with a time of flight of 13 seconds at 10,000 yards, 30 seconds at 20,000 yards, 53 seconds at 30,000 yards and 86 seconds at 40,000 yards.