From the Super Mario Wiki
A ? Coin, also known as a Question Coin, is a special Coin found in Super Mario Galaxy and Super Mario Galaxy 2. ? Coins appear in many galaxies throughout both games. When one is collected, it could cause any of the following things to appear:
Most of the time, Mario is given a time limit to collect whatever appears and if he is able to successfully collect it within the time limit, he will receive a prize. Most likely, it will be a 1-Up Mushroom, but it is also possible for it to be three 1-Up Mushrooms, a Power-up, more coins or Star Bits or, very rarely, a Rainbow Star.