From the Super Mario Wiki
Question Boxes have an identical appearance to a Question Block. Like the Propeller Box, they can be worn by Mario (or Luigi) over his body and stay with them until the end of the level. While inside a Question Box, infinite coins will pop out from it while Mario is walking, jumping or being launched from a cannon.
Question Boxes are only found in World 8-1, World 8-4 and Special 1-3. If Mario is touched by an enemy while wearing a Question Box, he loses it. If he touches a Flagpole while wearing one, it will disappear and give Mario an extra life.
In New Super Mario Bros. 2, similar objects known as Gold Blocks appear which give Mario/Luigi coins as a faster rate than the Question Boxes. Unlike Question Boxes, however, a Gold Block will disappear once 100 coins have been collected from it.