The cannons function much as the 'Warp Zones' of Mario yore. They allow you to skip a few of the world, generally jumping 4 ahead -- World 1 cannon takes you to Jungle World 5, for instance.
As to unlocking them, you must find the alternate exit (you can tell from the red ending flag) within one of the levels that make up the world, usually the level closest to the cannon itself. If you edit your question to specify which world you're interested in, I can drudge up some more details.
Collecting all three star coins on every level in a particular world opens up a corresponding secret level in the correspondingly secret World 9. For example, if you get them all in world 3, you unlock world 9-3
You need to collect every star coin from all nine worlds to achieve the second and third of the five save file stars, which indicate how much of the game you have completed.
You can also use them to buy videos like "super skills" Or "Star coin".
Best Answer
The cannons function much as the 'Warp Zones' of Mario yore. They allow you to skip a few of the world, generally jumping 4 ahead -- World 1 cannon takes you to Jungle World 5, for instance.
As to unlocking them, you must find the alternate exit (you can tell from the red ending flag) within one of the levels that make up the world, usually the level closest to the cannon itself. If you edit your question to specify which world you're interested in, I can drudge up some more details.