Minecraft wiki entry for TNT_cannons, associated text: For maximum range, you want there to be an about 30 degree trajectory but with the least possible amount of matter (blocks) in between the charge and the shot, that way more of the charge's explosion reaches the shot.
So it's best for TNT cannons to be elevated off the ground depending on the wanted range of the cannon.
For shooting arrows, sand/gravel, anvils, or mobs, a piston might be needed to drop the said ammunition.